Thursday, September 13, 2018

FOR LOOP PROCESSING

  • Problem Description

    Program to calculate the sum of first n natural numbers
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int n,i,sum=0;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
        {
        sum=sum+i;
      }
      printf ("%d",sum);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    10
    
    
    Expected Output
    55
  • Test Case 2

    Input (stdin)
    5
    
    
    Expected Output
    15

No comments:

Post a Comment