Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Print Pattern 1*2*3*4 9*10*11*12 13*14*15*16

For any input Number N print the following code – for below code N=4.

          1*2*3*4
          9*10*11*12
          5*6*7*8
          13*14*15*16

Basic incrementing Squared Number-Star Pattern + Basic incrementing inverted Squared Number-Star Pattern (alternate)

Had N value been 5

Then output –

1 * 2 * 3 * 4 * 5 
11 * 12 * 13 * 14 * 15 
21 * 22 * 23 * 24 * 25 
16 * 17 * 18 * 19 * 20 
6 * 7 * 8 * 9 * 10

Code in C

[code language=”cpp”]

#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the Number of Rows : ";
cin>>n;
int p=n;
if(n>=1 && n<=100)
{
for(int i=1;i<=n;i+=2)
{
int k=(i-1)*n+1;
for(int j=0;j<n-1;j++)
{
cout<<k<<" * ";
k++;
}
cout<<k<<" ";
cout<<endl;
}
if(n%2!=0)
{
p=n-1;
}
for(int i=p;i>0;i-=2)
{
int k=(i-1)*n+1;
for(int j=0;j<n-1;j++)
{
cout<<k<<" * ";
k++;
}
cout<<k<<" ";
cout<<endl;
}
}
else
{
cout<<"Enter a Valid Input(1-100)!";
}
return 0;
}
[/code]