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.
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:
  • 1T20
  • 1N1000

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 3
1
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

Popular posts from this blog

Export data from mysql db to csv file using java

Secure Database Connectivity in node.js with mysql

Java Web Scraping