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 numbersTest Case 1
Input (stdin)10
Expected OutputSum=55
Test Case 2
Input (stdin)20
Expected OutputSum=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.