摘要:
/* 输入一个正整数n,求n! */#includeint main(void){ int i,n; double product; printf("Enter n:"); scanf_s("%d",&n); product=1; for(i=1;i<=n;i++){ product=product*i; } printf("product=%.0f\n",product); return 0;} 阅读全文
摘要:
/* 计算1-1/3+1/5-1/7+… 共n项之和 */#includeint main(void){ int denominator,flag,i,n; double item,sum; printf("Enter n:"); scanf_s("%d",&n); flag=1; denominator=1; sum=0; for(i=1;i<=n;i++){ item=flag*1.0/denominator; sum=sum+item; flag=-flag; denominator=... 阅读全文
摘要:
/* 计算1+2+3+…+n */#includeint main(void){ int i,n,sum; printf("Enter n:"); scanf_s("%d",&n); sum=0; for(i=1;i<=n;i++){ sum=sum+i; } printf("Sum of numbers from 1 to %d is %d\n",n,sum); return 0;} 阅读全文