计算两个数之间的整数的和

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main(void)
{
	int n1, n2;
	int sum = 0;
	puts("请输入两个整数:");
	printf("整数1:"); scanf("%d", &n1);
	printf("整数2:"); scanf("%d", &n2);
	switch (n1 > n2) {
	case 1: { int t = n2;
		do {
			sum = sum + t;
			t = t + 1;
		} while (t <= n1);
		printf("大于等于%d小于等于%d的所有整数的和是%d。\n", n2, n1, sum); break;
	case 0: {int t = n1;
		do {
			sum = sum + t;
			t = t + 1;
		} while (t <= n2);
		printf("大于等于%d小于等于%d的所有整数的和是%d。\n", n1, n2, sum); break;
	}
	}
	}
	return 0;
}

你可能感兴趣的:(学习笔记,c++)