比較兩數的大小,計算小數依次加到大數的和

運行結果換行,只用了std::endl; 實際看資料有“/r/n”,實際怎麼用,沒看出效果來。。。笨啊。。


#include <iostream>
int main ()
{
	int v1,v2,lower,upper ;
	std ::cout <<"enter two numbers:"<<std ::endl ;
	std ::cin >>v1 >> v2 ;
	if( v1 >v2 )
	{ lower =v2 ;upper =v1 ;}
	else { lower =v1  ;upper = v2 ;}
	int sum=0;
	for (int val =lower ;val <=upper ; val ++)
		sum += val ;
	std ::cout <<"the lower is "<<lower <<std ::endl ;
	std ::cout <<"the upper is " <<upper <<std ::endl ;
	std ::cout <<"the sum from "<<lower<<" to "<< upper <<" is " << sum << std ::endl ;
	system ("pause");
	return 0;
}

運行結果


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章