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

Chowdhury Md. Ishmam Rahman all is ok,but why getting wrong answer??C language [1] // Problem 1068. Sum 7 Oct 2017 11:23
#include<stdio.h>
#include<math.h>
int main()
{
    int i,sum=0,n;
    scanf("%d",&n);

    if(abs(n)<=10000){

    if(n<0){

    for(i=1;i>=n;i--){
        sum+=i;
    }
    }

    else{
        sum=((n*n)+n)/2;
    }

    printf("%d",sum);}
    return 0;
}
Peal Mazumder Re: all is ok,but why getting wrong answer??C language // Problem 1068. Sum 28 Oct 2017 12:00
Your code is almost okay.It's wrong only for one test case. When n=0 then according to your code output will be 0.But right answer is 1. Please check again output condition of this problem.

Otherwise https://ideone.com/Q6C1gh