现在的位置: 首页 > 基础课程 > 正文

循环结构进阶

2011年04月09日 基础课程 ⁄ 共 454字 ⁄ 字号 暂无评论

2 要求输出100~200之间的不能被3整除的数

1
2
3
4
   1   2   3   4   5
   2   4   6   8  10
   3   6   9  12  15
   4   8  12  16  20

其实不用 continue 也可以达到同样的效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#define SUM 100000
int main()
{
    float amount,aver,total;
    int i;
    for (i=1,total=0; i<=1000; i++) {
        printf("please enter amount, student %4d = ", i);
        scanf("%f",&amount);
        total= total+amount;
        if (total>=SUM) break;
    }
    aver=total/i;
    printf("num=%dnaver=%10.2fn",i,aver);
    return 0;
}
【上篇】
【下篇】

抱歉!评论已关闭.