Home  >  Article  >  Backend Development  >  C language calculates the sum of factorials from 1 to n

C language calculates the sum of factorials from 1 to n

王林
王林Original
2020-05-11 10:17:0416823browse

C language calculates the sum of factorials from 1 to n

Write the header file

#include<stdio.h>

Write the main function.

C language calculates the sum of factorials from 1 to n

#Define sum in the main function using long long, and the defined n is the final factorial number you require.

C language calculates the sum of factorials from 1 to n

Then use a for loop to find the sum of factorials of 1 2! .... n!

C language calculates the sum of factorials from 1 to n

Test whether Correct, when I enter 5, the result is as follows:

C language calculates the sum of factorials from 1 to n

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn