ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

Why WRONG ANSWER c++
Posted by Daniel 5 Oct 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++
Posted by daftcoder [Yaroslavl SU] 6 Oct 2011 13:35
You outputs 0 on test 0 when should be 1.
Re: Why WRONG ANSWER c++
Posted by navi1893 21 Jun 2012 05:37
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;
}