To calculate the factorial of a number:
#include <stdio.h>
int main ()
{
int n,i;
scanf ("%d", &n);
for (i=n-1;i>0;i--)
{
N=n*i;
}
printf ("%d", n);
return 0;
}
Calculate 1! +2! +3! +...+10!
#include <stdio.h>
int main ()
{
int a,b,c;
int sum=0;
for (a=1;a<=10;a++)//control of 1-10 digits
{
for (b=1,c=1;b<=a;b++)//control the factorial of each number
{
C=b*c;
}
sum+=c;//the result in sum
}
printf ("%d", sum);
return 0;
}
Using a loop to find 1-10 factorial and
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int num = 1;
int i = 0;
int sum = 0;
for (i = 1; i <=; i++)
{
int TMP = i;//defines a temporary variable to hold I (because the variables inside the for loop cannot be arbitrarily modified)
num = num *tmp;
sum + = num;
}
printf ("%d\n", sum);
return 0;
This article is from the "Sunflower in the Sun" blog, please be sure to keep this source http://10796797.blog.51cto.com/10786797/1706958
Computes the factorial of N and its summation (multiple methods) using the C language