2.使用for循环和do…while循环计算大于100、小于200的自然数之和

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 17:40:44

2.使用for循环和do…while循环计算大于100、小于200的自然数之和
2.使用for循环和do…while循环计算大于100、小于200的自然数之和

2.使用for循环和do…while循环计算大于100、小于200的自然数之和
int sum = 0;
for (int i = 101; i < 200; i++)
{
sum += i;
}
// 此处输出sum
int result = 0;
int index = 101;
do
{
result += index;
index++;
} while (index < 200);
// 此处输出result