|
|
back to boardDiscussion of Problem 1068. Sumwhy 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 Posted by Ehab 20 Nov 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; |
|
|