计算正整数m到n的和
//输入两个正整数,求m加到n的和
#include <stdio.h>
int main()
{
int m, n, x;
printf("输入m和n \n");
scanf("%d %d", &m, &n);
//如果m<n,将m和n交换
if (m > n){
x = m;
m = n;
n = x;
}
//sum从m开始算起,逐步向上加
int sum = m;
while (m < n){
m += 1;
sum += m;
//printf("m=%d, sum=%d\n", m, sum);
}
printf("m到n的和为%d", sum);
return 0;
}