Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int sum_num = 0;
- int input;
- cout << "Enter a positive, non-zero integer\n";
- cin >> input;
- if (input>0)
- {
- for (int x = 1; x <= input; x++)
- {
- sum_num += x;
- }
- cout << "Sum of numbers from 1 to ";
- cout << input << " is " << sum_num << endl;
- }
- else if (input == 0)
- {
- cout << "Hey, I said non-negative\n";
- }
- else
- {
- cout << "Hey, I said positive\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment