Pattern Practice 2
There is a number N.You have to Generate a pattern from this number N.
Pattern from N will be like below pattern.
Pattern from N will be like below pattern.
1 23 456 ........ .......... ...........(N-1)N.
Input
- The first line of the input contains an integer T denoting the number of test cases.
- The first line of each test case contains a single integer N denoting the number for pattern
Output
- For each test case, output contains a single pattern .
Constraints
Should contain all the constraints on the input data that you may have. Format it like:- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 1000
Example
Input: 2 3 6 Output: 1 23 1 23 456
Explanation
Example case 1. Number for pattern is 3 So pattern will be upto 31 23
Solution
#include<stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i,j,k,num,T,flag;
scanf("%d",&T);
while(T--)
{
k=1;flag=1;
//printf("");
scanf("%d",&num);
i=1;
while(i)
{
for(j=0;j<i;j++)
{
if(k>num){flag=0;break;}
printf("%d",k++);
}
if(flag==0) {break;}
else printf("\n");
i++;
}//printf("\n");
}
return 0;
}
Comments
Post a Comment