和楼主程序差不多,少几行代码,版主能否给加个分?{:3_64:}
- #include <stdio.h>
- int main()
- {
- int num;
- long sum = 0;
- int count = 0;
- printf("输入一个正整数(输入负数结束):");
- scanf("%d", &num);
- while (num >= 0)
- {
- ++count;
- sum += num;
- printf("sum = %d, avg = %.2f\n", sum, (float)sum / count);
- printf("输入一个正整数(输入负数结束):");
- scanf("%d", &num);
- }
- return 0;
- }
复制代码
|