Canna

Thursday, 27 September 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
  • Test Case 1

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

    Input (stdin)
    20
    
    
    Expected Output
    Sum=210
  • Program
  • #include <stdio.h>
    int main()
    {
      int n,i,sum=0;
      scanf("%d",&n);
      for(i=0;i<=n;i++)
      sum=sum+i;
      printf("Sum=%d",sum);
      
    
     return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.