Home > Article > Backend Development > C language calculates the sum of factorials from 1 to n
Write the header file
#include<stdio.h>
Write the main function.
#Define sum in the main function using long long, and the defined n is the final factorial number you require.
Then use a for loop to find the sum of factorials of 1 2! .... n!
Test whether Correct, when I enter 5, the result is as follows:
Recommended tutorial: c language tutorial
The above is the detailed content of C language calculates the sum of factorials from 1 to n. For more information, please follow other related articles on the PHP Chinese website!