#include stdio.hint main(void){int count, sum;int n;printf(Enter the upper limit: );
编程学习网为您整理以下代码实例,主要实现:从用户读取上限,使用while循环查找前n个整数的总和,希望可以帮到各位朋友。
#include <stdio.h>
int main(voID)
{
int count, sum;
int n;
printf("Enter the upper limit: ");
scanf("%d", &n);
count = 0;
sum = 0;
while (count++ < n)
sum = sum + count;
printf("sum = %d\n", sum);
return 0;
}