开始最先想到
#include<stdio.h>
int main()
{
int n=0;
int i = 1;
int nj=1;
printf("输入n=");
scanf("%d", &n);
if (n == 0)
{
printf("n!=0\n");
}
if (n != 0)
{
for (i = 1; i <= n; ++i)
{
nj = i*nj;
}
printf("n!=%d\n", nj);
}
system("pause");
return 0;
}
后来发现可以用while简单的达到目的
#include<stdio.h>
int main()
{
int n=0;
int i = 1;
int nj=1;
printf("输入n=");
scanf("%d", &n);
if (n == 0)
{
printf("n!=0\n");
}
if (n != 0)
{
while (i <= n)
{
nj = i*nj;
i++;
}
printf("n!=%d\n", nj);
}
system("pause");
return 0;
}