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

i got AC in C..
Posted by Suparna 11 Jan 2019 16:21


int num,n,i,sum=0;
     // read n;

//case 1
       if(n>0){
            for(i=1;i<=n;i++){
            sum=sum+i;
        }
         printf("%d",sum);
        }
//case 2
        if(n<0){
             for(i=(-1);i>=n;i--){

            sum=sum+i;
        }
            sum=sum+1;
            printf("%d",sum);
        }
//case 3
        else if(n==0){
            printf("1");
        }

        }




Re: i got AC in C..
Posted by mdatik 26 Aug 2019 23:16
when n<0,then sum=sum+1;
why you using sum=sum+1;
Re: i got AC in C..
Posted by Jolok Banarjee 18 Dec 2022 20:07
#include<stdio.h>

int main()
{
int num,n,i,sum=0;
scanf("%d", &n);

       if(n>0){
            for(i=1;i<=n;i++){
            sum=sum+i;
        }
         printf("%d",sum);
        }
        if(n<0){
             for(i=n;i<=1;i++){

            sum=sum+i;
        }

            printf("%d",sum);
        }
        else if(n==0){
            printf("1");
        }

        }