用while语句与do-while语句求1到20的阶乘的和

2024-11-29 22:51:42
推荐回答(1个)
回答1:

/*用while语句语句求1到20的阶乘的和*/ #include #define N 20 void main() { int i, sum, sum1; sum = 1; i = 2; while (i <= N) { sum1 = sum1 * i; sum = sum + sum1; i++; } printf("sum = %d",sum); } /*用do-while语句求1到20的阶乘的和*/ #include #define N 20 void main() { int i, sum, sum1; sum = 1; i = 2; do { sum1 = sum1 * i; sum = sum + sum1; i++; } while (i <= N); printf("sum = %d",sum); } 格式完全没问题的。。拿到TC2里面运行就好了。