题解 | #n的阶乘#
n的阶乘
https://www.nowcoder.com/practice/97be22ee50b14cccad2787998ca628c8
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main() {
//n的阶乘
int a=0;
while ((scanf("%d", &a)) != EOF)
{
int i = 0;
long long int sum=1;//这里注意用longlong来接收,要不然太大了,数据会出错;
for (i = 1; i <= a; i++)
{
sum *= i;
}
printf("%lld", sum);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main() {
//n的阶乘
int a=0;
while ((scanf("%d", &a)) != EOF)
{
int i = 0;
long long int sum=1;//这里注意用longlong来接收,要不然太大了,数据会出错;
for (i = 1; i <= a; i++)
{
sum *= i;
}
printf("%lld", sum);
printf("\n");
}
return 0;
}