Friday, May 3, 2019

PRINT SERIES

  • Problem Description

    Vishu has a task to solve the following series. Write a C code to find the print
    1+(1+2)+ (1+2+3)+ (1+2+3+4)++n. It will help him to come out of this problem. 
    Input:
    Input should contain the value of the limit n
    Output:
    It should print the above series upto n limit
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int n,s=0,i,j;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
        s=0;
        for(j=1;j<=i;j++)
          s+=j;
        printf("%d ",s);
      }

    return 0;
    }
  • Test Case 1

    Input (stdin)
    4

    Expected Output
    1 3 6 10
  • Test Case 2

    Input (stdin)
    10

    Expected Output
    1 3 6 10 15 21 28 36 45 55

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...