|
|
вернуться в форумWhy WRONG ANSWER c++ Послано Daniel 5 окт 2011 12:36 #include <iostream> int main() { int n,i; std::cin>>n; int sum=0; if(n<0) { for(i=n;i<=1;i++) sum+=i; std::cout<<sum;
} else {
for(i=n;i>=1;i--) sum+=i; std::cout<<sum; } return 0;} Re: Why WRONG ANSWER c++ You outputs 0 on test 0 when should be 1. Re: Why WRONG ANSWER c++ try so ;) #include <iostream> #include <cmath> using namespace std; int main() { int a, sum = 0; cin >> a; if( a > 0 ) { for ( int i = 1; i <= a; i++) sum += i; } else { for (int i = 1; i <= abs(a); i++) sum += i; sum = 1 - sum; } cout << sum; return 0; } |
|
|