Decode the logic and print the Pattern that corresponds to given input.
If N= 3
then pattern will be :
10203010011012
**4050809
****607
If N= 4, then pattern will be:
1020304017018019020
**50607014015016
****809012013
******10011
Constraints
2 <= N <= 100
Input Format
First line contains T, the number of test cases Each test case contains a single integer N
Output
First line print Case #i where i is the test case number In the subsequent line, print the pattern
Test Case 1
3
3
4
5
PROGRAM:
#include<stdio.h>
int main()
{
int n;
int test;
scanf("%d", &test);
for(int t=1; t<=test; t++){
printf("Case #%d\n",t);
scanf("%d", &n);
int sum = n*(n+1)/2;
int limit = sum*2;
int val1 = 1;
int val2=0;
int star=0;
for(int i=n; i>=1; i--){
for(int s=0;s<star; s++){
printf("*");
}
star+=2;
for(int j=1; j<= i; j++){
// if(j != i)
printf("%d0", val1);
// else
// printf("%d", val1);
val1++;
}
val2 = (i-1)*i/2;
for(int k=sum+1+val2; k<=limit; k++){
if(k != limit)
printf("%d0",k);
else
printf("%d",k);
}
limit = limit - i;
printf("\n");
}
}
return 0;
}
3
Case #1
3
10203010011012
**4050809
****607
Case #2
4
1020304017018019020
**50607014015016
****809012013
******10011
Case #3
5
102030405026027028029030
**6070809022023024025
****10011012019020021
******13014017018
********15016
No comments:
Post a Comment