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

Why wrong ?
Posted by Pranto Das 20 Nov 2016 19:12
#include<stdio.h>
#include<math.h>

int main()
{
    int N;

    scanf("%d",&N);

    int i,ck = 0;
    for(i = 2; i <= abs(N); i++)
        ck += i;

    if(N < 0)
        printf("-%d\n",ck);
    else
        printf("%d\n",ck);

    return 0;
}
Re: Why wrong ?
Posted by Aman 5 Apr 2017 22:33
This question is basically a problem of finding sum of all numbers between 1 to N where N can be either <0 or > 0. We can solve this problem in multiple ways like using a loop or using recursion.
http://www.techcrashcourse.com/2014/10/c-program-to-add-n-numbers.html
http://www.techcrashcourse.com/2014/10/c-program-add-two-numbers.html