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);
循环 while do---while,布布扣,bubuko.com
时间: 2024-10-10 09:05:49