-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif.cpp
More file actions
43 lines (38 loc) · 834 Bytes
/
if.cpp
File metadata and controls
43 lines (38 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: if.cpp
* Author: fredzhao
*
* Created on 2017年2月12日, 下午1:11
*/
#include <iostream>
/*
*
*/
int main(int argc, char** argv) {
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;
int val=0;
for (val=lower;val<=upper;++val)
sum = sum+val;
std::cout << "Sum of " << lower
<< " to " << upper
<< " inclusive is "
<< sum << std::endl;
return 0;
}