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

WA TEST #2
Posted by Yuriy 19 Feb 2012 17:13
tell me what's wrong in my code ???


#include <stdio.h>
#include <math.h>
void main ()
{
    long N=-1,sum=0;
    int i=0;
    scanf("%d",&N);
    if (abs(N)<=10000)
    {
    if (N>0)
    {
    for (i=N;i>1;--i)
    {
    sum+=i;
    }
    }
    else if (N<0)
    {
        for (i=N;i<-1;++i)
        {
            sum+=i;
        }
    }
    printf("%ld",sum);
    }
}
Re: WA TEST #2
Posted by papkov_nikita 22 Feb 2012 02:08
for (i=N;i<-1;++i)
"лежащих между 1 и N включительно."
may be because 1 != -1 ?
for(i=N;i<=+1;i++)


Edited by author 22.02.2012 02:08
Re: WA TEST #2
Posted by Misha ignatyuk 7 Mar 2012 18:11

Edited by author 07.03.2012 18:11

Edited by author 07.03.2012 18:11
Re: WA TEST #2
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;
}