Saturday, August 25, 2018

SUM OF NATURAL NUMBERS

  • Problem Description

    write a c Program to calculate the sum of first n natural numbers and Positive integers 1,2,3...n are known as natural numbers
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int i,sum=0,n;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
        sum=sum+i;
      }
      printf("Sum=%d",sum);
      return 0;
    }
  • Test Case 1

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

    Input (stdin)
    20
    
    
    Expected Output
    Sum=210

No comments:

Post a Comment