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

help!
Posted by chenxiang 25 Nov 2006 14:45
what is wrong with this code.
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,i;long long int sum=0;
    scanf("%d",&n);
    if(n>=1)
    {
        for(i=1;i<=n;i++)
            sum=sum+i;
    }
    if(n<0)
    {
         for(;n<=1;n++)
              sum=sum+n;
    }
    printf("%ld \n",sum);
    system("pause");

}
why i got wa?
Re: help!
Posted by <>|>|/|<|>>|<<>|-| 26 Nov 2006 08:16
if(n>0)
  {
  for(int i=1;i<=n;i++)
   sum=sum+i;
   }
   else
  {
  for(int j=n;j<=1;j++)
   sum=sum+j;
   }
Accepted
Posted by Undead 19 Nov 2007 02:09
int main(int argc, char* argv[])
{
        int n,i,c;
        scanf("%d",&n);
        c=0;
        if (n>0)
                for (i=1;i<=n;i++)
                        c=c+i;
        if (n<0)
                for (i=n;i<=1;i++)
                        c=c+i;
        if (n==0)
                c=1;
        printf("%d",c);
        getch();
        return 0;
}
Re: help!
Posted by sakib hasan 28 Jul 2010 12:44