计算并输出1!+2!+3!….+n!(嵌套循环)

  • Post author:
  • Post category:其他



计算并输出1!+2!+3!….+n!(嵌套循环)


#include<stdio.h>


int main()


{


int i, n;


long sum = 0;


long p=1;


printf(“Please enter n:”);


scanf_s(“%d”, &n);    //

VS里面scanf后面要加_s


for (i = 1; i <= n; i++)


{


p = p * i;        //阶乘


sum = sum + p;      //阶乘的和累加


}


printf(“sum= %ld”, sum);


return 0;


}



版权声明:本文为shadoubudong_666原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。