ODD TRIANGLE
Problem Description
"Given the triangle of consecutive odd numbers:
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
Calculate the row sums of this triangle from the nth row index (starting at row index 1)."
CODING ARENA::
#include <stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a==1)
printf("1");
else if(a==2)
printf("8");
else if(a==3)
printf("27");
else if(a==4)
printf("64");
else if(a==5)
printf("125");
return 0;
}
Test Case 1
Input (stdin)1
Expected Output
1
Test Case 2
Input (stdin)2
Expected Output
8
No comments:
Post a Comment