|
|
вернуться в форумwhy wrong answer #include <iostream> using namespace std; int sum(int a) { return ((1 + a)/2)*a; } int main () { int a;
cin >> a;
if (a > 0) cout << sum(a); else if (a < 0) cout << sum(abs(a)) * -1 + 1; else cout << 0;
return 0; } Re: why wrong answer Послано Ehab 20 ноя 2023 02:23 if N = 0 then you need add one so the correct solution is: if (a > 0) cout << sum(a); else if (a < 0) cout << sum(abs(a)) * -1 + 1; else cout << 1; |
|
|