标签:循环
1 计算1+2+3...+99+100的和.
a--- int sum = 0,i = 0;
while (i < 101) {
sum = sum + i;
i++;
}
printf("%d",sum);
b--
int sum = 0,i = 1;//存储值
do {
sum = sum + i;//现执行一次循环体,在判断条件
i++;
} while (i < 101);
printf("%d",sum);
2
//100以内13倍数之和
int sum = 0,i = 1;
while (i < 101) {
if (i % 13 == 0) {//对13取余
printf("%d",i);
sum = sum + i;
}
i++;
}
printf("\n%d",sum);
本文出自 “久久归一” 博客,请务必保留此出处http://lulun426.blog.51cto.com/9197884/1534211
循环 while do---while,布布扣,bubuko.com
标签:循环
原文地址:http://lulun426.blog.51cto.com/9197884/1534211