#include "stdio.h"#include "conio.h"
main(){ int n,i,sum,p; p=1;sum=0; for(n=1;n<=5;n++) {for(i=1;i<=n;i++) p=p*i;} sum=sum+p; printf("1!+2!+3!+4!+5!=%d\n",sum);
getch();}
修改后的程序如下:#include <stdio.h>main(){ int n,i,p,sum; sum=0; for(n=1;n<=5;n++) {for(i=1,p=1;i<=n;i++) /*p应该放在 for 循环里面*/ p=p*i; sum=sum+p; } printf("1!+2!+3!+4!+5!=%d\n",sum);
getchar();}
look #include "stdio.h"#include "conio.h"
void main(){ int n,sum,p; p=1; sum=0; for(n=1;n<=5;n++) { p=p*n; sum=sum+p; } printf("1!+2!+3!+4!+5!=%d\n",sum);