Home  >  Article  >  Backend Development  >  C language to calculate the cumulative sum of factorials

C language to calculate the cumulative sum of factorials

王林
王林Original
2020-05-13 10:45:549339browse

C language to calculate the cumulative sum of factorials

Specific code:

# include "stdio.h"
void main()
{
  int n,i,j,sum=0,t=1;
  printf("please enter a number:");
  scanf("%d",&n);
  for(i=0;i<n;t=1,i++)   //这里的循环事件是重点!每循环一次重新给t赋值。
    { 
       for(j=n-i;j>0;j--)
    {
t*=j;
}
   sum+=t;
   }
   printf("\n1!+....+%d!=%d",n,sum);
}

Recommended tutorial: c language tutorial

The above is the detailed content of C language to calculate the cumulative sum of factorials. 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