Thursday, May 2, 2019

Continuous Sum

  • Problem Description

    Chintu is confusing himself with series of numbers. He has to find the sum of the following series. Your task is to write a code to find the sum of the following series
    1+(1+2)+ (1+2+3)+ (1+2+3+4)++n
    Input:
    Input should contain the value of the limit n
    Output:
    It should print the Sum of series upto n limit
  • Test Case 1

    Input (stdin)
    2

    Expected Output
    Sum of series=4
  • Test Case 2

    Input (stdin)
    4

    Expected Output
    Sum of series=20
Solution

#include <stdio.h>
int main(){
int n,sum,sum1=0,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
sum=0;
for(j=1;j<=i;j++)
sum=sum+j;
sum1=sum1+sum;
}
printf("Sum of series=%d",sum1);
return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...