Problem Description
Vishu has a task to solve the following series. Write a C code to find the print
1+(1+2)+ (1+2+3)+ (1+2+3+4)++n. It will help him to come out of this problem.
Input:
Input should contain the value of the limit n
Output:
It should print the above series upto n limitCODING ARENA
#include <stdio.h>
int main()
{
int n,s=0,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=0;
for(j=1;j<=i;j++)
s+=j;
printf("%d ",s);
}
return 0;
}
Test Case 1
Input (stdin)4
Expected Output1 3 6 10
Test Case 2
Input (stdin)10
Expected Output1 3 6 10 15 21 28 36 45 55
No comments:
Post a Comment