程序运行没有错误,却得不到想要得结果

来源:百度知道 编辑:UC知道 时间:2024/05/20 05:42:14
下面的程序是我编写的5的阶乘.答案却不对.我不知道错在哪里?求各位高手前辈救救我... ...
/* Note:Your choice is C IDE */
#include "stdio.h"

main()
{
int a,b,c;
a=1,b=0,c=0;
while (a<5)
{
b=a*(a+1);
c=c+b;
}
printf("%d",c);

}

#include "stdio.h"

main ()
{
int a=1,b=1;
while (a<5)
{
b=b*(a+1);
a++;
}
printf("%d",b);
}

你的程序是个死循环啊~
while 的循环条件是a<5但是在循环里面并没有对a这个变量做变化啊~
当然得不出你要结果了
而且你对5的阶乘理解有问题吧,5!=5×4×3×2×1
楼上的程序就OK的,理解一下吧~