下面程序是0-19的和;
如果计算1-20的和只需把count=1即可
int count = 0;
程序如下:
#include<stdio.h>
int main()
{
int count = 0;
int sum = 0;
while (count <20)
{
sum = sum + count;
count++;
}
printf("%d\n", sum);
return 0;
}
输出结果如下:
下面程序是0-19的和;
如果计算1-20的和只需把count=1即可
int count = 0;
程序如下:
#include<stdio.h>
int main()
{
int count = 0;
int sum = 0;
while (count <20)
{
sum = sum + count;
count++;
}
printf("%d\n", sum);
return 0;
}
输出结果如下: