ITGUY90 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.

Program:

#include<bits/stdc++.h>
using namespace std;
 
int main()
 {
	//code
	
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
	     int x = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++)
                cout<<'*';
            for (int k = 1; k < 2 * i; k++) {
                if (k <= i)
                    cout<<x - (i - k);
                else
                    cout<<x + (i - k);
            }
            for (int j = 1; j <= n - i; j++)
                cout<<'*';
            x = x + 2;
            cout<<"\n";
        }
	}
}