c - 为什么它不起作用(Dev C++ 中的 C Lang)

标签 c crash console factorial

请告诉我,这里出了什么问题,它可以编译,但当我输入数字时控制台崩溃。我不知道接下来要写什么,我只会写一些东西来使我的帖子成为可能。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{
    unsigned int i,l,p,w;
    printf("Enter natural number excluding 0: ");
    scanf("%d",l);
    p = 1;
    for(i=1;i<=l;i++)
    {
        p=p*i;
    }
    w=p;
    printf("\nFactorial of entered number %d",w);
    return 0;
}

最佳答案

scanf("%d",l);需要插入l的地址,即&l

您还应该使用 %u 表示无符号整数,而不是 %d

关于c - 为什么它不起作用(Dev C++ 中的 C Lang),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23375975/

相关文章:

c++ - 如何在 OS X 上获取 USB 驱动器的硬盘驱动器序列号?

c - 我的 Sublime Text 构建系统,在当前文件夹中运行 build.sh

crash - 总线错误的可能原因:物理地址不存在

如果我更改 <uses-sdk> 详细信息,Android 应用程序会崩溃

PowerShell 作业与启动进程

c# - C++ 到 C# : cin to Console. 读取

c - 在C中打印二维数组

无法通过 C 中的 fwrite 和 fread 复制文本文件

crash - UIWebDocumentView _updateSubviewCaches 在 iOS10 中崩溃

ios - 谷歌分析 3.08 IOS idfa 类丢失,不会收集 idfa