c语言while循环控制循环次数


 

1、

#include <stdio.h>

int main(void) { int num; int counts = 0, sum = 0; int temp; puts("please input an integer."); printf("num = "); scanf("%d", &num); while ( counts < num) { counts = ++counts; printf("NO%d = ", counts); scanf("%d", &temp); sum = sum + temp; } printf("sum = %d.\n", sum); printf("mean = %f.\n", (double)sum / counts); return 0; } 

 ↓

#include <stdio.h>

int main(void) { int num, temp; int counts = 0, sum = 0; puts("please input an num."); printf("num = "); scanf("%d", &num); while (counts < num) { printf("NO.%d = ", ++counts); scanf("%d", &temp); sum = sum + temp; } printf("sum = %d.\n", sum); printf("mean = %f.\n", (double)sum / counts); return 0; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM