ITGUY80 - 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 sum(int n) {
        if (n <= 0)
            return 0;
        else
            return (n * (n + 1) / 2);
    }
int main()
 {
	//code
	
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
	     for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i + 1; j++) {
                if (j != i + 1)
                    cout<<(j - 1) * n + i - sum(j - 1);
                else
                    cout<<'*';
            }
        cout<<"\n";
        }
	}
}