标签:打印 algorithm 指定 std ber opened += val 技术
编写程序:提示用户输入两个整数,打印出这两个整数所指定的范围内的所有整数。
1 #include <iostream> 2 #include <algorithm> 3 int main() 4 { 5 std::cout<<"Enter two numbers:"<<std::endl; 6 int sum = 0, val = 0, a = 0, b = 0, min = 0, max = 0; 7 std::cin>>a>>b; 8 min = std::min(a,b), max = std::max(a,b),val = min; 9 while (val <= max) 10 { 11 sum += val; 12 ++val; 13 } 14 std::cout<<"The sum of "<<min<<" to "<<max<<"inclusive is "<<sum<<std::endl; 15 system("pause"); 16 return 0; 17 }
标签:打印 algorithm 指定 std ber opened += val 技术
原文地址:https://www.cnblogs.com/archerzon/p/9517843.html