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

who can help me ?
Posted by xiaowentao99 13 Mar 2009 17:38
my cpp file
#include <stdio.h>

int main(){
    int num;
    int answer;
    scanf("%d",&num);
    if(num>=0){
    for(;num>=1;num--)
    answer += num;
    }
    else{
    for(;num<=-2;num++)
    answer += num;
    }
    printf("%d\n",answer);
    return 0;
    }
where is the wrong ?
Re: who can help me ?
Posted by Alias aka Alexander Prudaev 13 Mar 2009 18:41
1) int answer;  // wrong
int answer = 0; // right
2) for 0 answer is 1, not 0
Re: who can help me ?
Posted by xiaowentao99 13 Mar 2009 18:54
thank you ! I have known where is wrong .thank you all the same!