|
|
вернуться в форум#include <iostream> using namespace std; int main() { int n, res = 0; cin >> n; if (n < 0) { for (int i = -2; i >= n; i--) { res = res + i; } cout << res; } else { for (int i = 1; i <= n; i++) { res = res + i; } cout << res; } return 0; } int i = -2; i >= n; i-- i = 1 Optimization trick with initial i=-2 is funny. But now you aren't processing case "n == 0" correctly. if(n == 0) --> ans = ? bro.. i don't understand... i'm from vietnam Lets read task: > sum of all integer numbers lying between 1 and N inclusive If N==0 then set of integers to sum is [0..1], sum is 1. |
|
|