# Pattern type-2

Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

Math .

# PROBLEM:

For given size of N print the following pattern

# EXPLANATION:

see the pattern according to it print the following pattern
for n=4

``````7*8*9*10
4*5*6
2*3
1
``````

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
// cout<<to_string(c) +"*";
c++;
}
else{
// cout<<to_string(c);
c++;
}
}//cout<<"\n";
}
//cout<<c;
c=c-n;

for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +"*";
c++;

``````  }
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2*i;
cout<<"\n";
``````

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
// cout<<to_string(c) +"*";
c++;
}
else{
// cout<<to_string(c);
c++;
}
}//cout<<"\n";
}
//cout<<c;
c=c-n;

for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +"*";
c++;

``````  }
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2*i;
cout<<"\n";
``````

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
// cout<<to_string(c) +"*";
c++;
}
else{
// cout<<to_string(c);
c++;
}
}//cout<<"\n";
}
//cout<<c;
c=c-n;

for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +"*";
c++;

``````  }
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2*i;
cout<<"\n";
``````

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}