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

What's wrong with my code?
Posted by Александр 10 Oct 2012 02:14
#include<stdio.h>
#include<conio.h>
int main()
{
    int a, sum = 0;
scanf("%d",&a);
    if( a > 0 )
    {
        for ( int i = -1; i <= a; i++)
        sum += i;
    }

    else
    {
        for (int i = 1; i <= -a; i++)
        sum += i;
        sum = 1 - sum;
    }
printf("summa ravna %d",sum);
getch();
}
Re: What's wrong with my code?
Posted by tomkus 29 Nov 2012 02:23
first:
printf("summa ravna %d",sum);
use just:
printf("%d",sum);

second:
don't use:
getch();

third:
if A>0 sum from 1, not from -1