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

Where is my mistake?Tell me please.C++. WA# 9
Posted by Mihran Muradyan (Fizmat) 7 May 2009 17:20
#include"iostream.h"
double S,n,i;
int main()
{
    cin>>n;
    if(n==0)
        S=1;
    if(n>0)
        for(i=1;i<=n;i++)
            S=S+i;
    if(n<0)
        for(i=1;i>=n;i--)
            S=S+i;
    cout<<S<<endl;
    return 0;
}
Re: Where is my mistake?Tell me please.C++. WA# 9
Posted by Aram Taranyan (YSU) 7 May 2009 17:37
Mihran you must set value of S equal to zero,before "for(...) S=S+i;".Good luck!

Edited by author 07.05.2009 17:39
Re: Where is my mistake?Tell me please.C++. WA# 9
Posted by Надежда Халтурина 3 Apr 2011 20:40
why the compiler does not accept the job site?
that do not correctly?


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int N;
int H=0;
int S=0;
int i;

    cin>>N;
    if(((N<10000)&&(N>1))||((N>-10000)&&(N<-1)))
    {
    H=abs(N);
    for( i=2;i<=H;i++) S=S+i;
    if(N<0) cout<<endl<<S*(-1);
    else cout<<endl<<S;}
    else cout<<"error";
return 0;
}
Re: Where is my mistake?Tell me please.C++. WA# 9
Posted by psheno 3 Apr 2011 22:37
n=0