1.cpp

来自「在vc++语言环境下」· C++ 代码 · 共 33 行

CPP
33
字号

/**********chapter5 T1计算并输出两个整数间(包括这两个整数)所有整数之和*********/
#include<iostream>
int main()
{   
	using namespace std;
	int a,b;
	cout<<"Please input two integer.\n";
	cin>>a>>b;
	int sum=0;
	int temp;
	if (a>b)  //确定输入的两个整数的大小
	{	
		temp=a;
	     a=b;
	     b=temp;
	}


   if(a!=b)  //求和
   {
	for(int i=a;i<=b;i++)
	{
		sum+=i;

   }
   }
   else 
	   sum=2*a;
 
	cout<<"The sum of the integers between the the two integers is:"<<sum<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?