Problem Description
Program to calculate the sum of first n natural numbersCODING 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 Output55
Test Case 2
Input (stdin)5
Expected Output15
No comments:
Post a Comment