【发布时间】:2014-04-29 21:52:06
【问题描述】:
请告诉我,这里出了什么问题,它可以编译,但是当我输入数字时控制台崩溃。我不知道接下来要写什么,我只是写点东西让我的帖子成为可能。
#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的第二个参数应该是指向变量的指针,而不是变量本身。 -
获得更好的编译器。 GCC 打印:
warning: format '%d' expects type 'int *', but argument 2 has type 'unsigned int'