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 numbersCODING 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 OutputSum=55
Test Case 2
Input (stdin)20
Expected OutputSum=210
No comments:
Post a Comment