#include <iostream> #include <conio.h> int main(){ std::cout<<"Enter two numbers:"<<std::endl; int v1,v2; std::cin>>v1>>v2; int lower,upper; if(v1<=v2){ lower = v1; upper = v2; }else{ lower = v2; upper = v1; } int sum = 0; for(int val = lower;val<=upper;++val){ sum +=val; } std::cout<<"Sum of "<<lower<<"to"<<upper <<" is " <<sum<<std::endl; getch(); return 0; }
输入两个数
计算出,他们之间的和
例如输入1、3
计算1+2+3
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3723660.html,如需转载请自行联系原作者