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

wrong in test case 4 why?
Posted by asdfg 23 Dec 2019 12:16
#include <iostream>

using namespace std;

int main()
{
    int n,sum=0;
     cin>>n;
     if(n==0 || n==1)
    {
        cout<<1<<endl;
    }

   if(n>1)
   {
       for(int i=2;i<=n;i++)
   {

       sum=sum+i;
   }
       cout<<sum<<endl;
   }
   if(n<0)
   {
       n=n*-1;
       for(int i=2;i<=n;i++)
   {

       sum=sum+i;
   }
       cout<<"-"<<sum<<endl;
   }

    return 0;
}