#include<stdio.h>
main ()
{ int n, n1=1; unsigned n2=1; printf("scan a number>0: \n"); scanf("%d", &n); while(n1<=n) { n2*=n1; ++n1; } printf("%d! is %d \n", n, n2);
}
n2 的值超范围了,可以这样改
#include <stdio.h>
int main(int argc , char *argv[])
{ long long int n,n1 =1; long long int n2 = 1; scanf("%lld",&n); while(n1 <= n) { n2 *= n1; n1++; } printf("%lld! is %lld\n",n,n2); return 0;
}
n2这个变量溢出了,
#include<stdio.h>
main ()
{ int n, n1=1; double n2; printf("scan a number>0: \n"); scanf("%d", &n); while(n1<=n) { n2*=n1; ++n1; } printf("%d! is %d \n", n, n2);
}