C++ PROGRAMMING PATTERN
1.Introduction
2.Algorithm
3.Code
4.Conclusion
5.problem
By: Er. Raushan Kumar
1. INTRODUCTION
• C++—the popular and highly readable object-oriented
Programming language—is both powerful and relatively easy to
learn. Whether you're new to programming or an experienced
developer, this course can help you get started with C++. Er.
Raushan Kumar provides an overview of the Pattern program,
basic Algorithm, and an example of how to construct and run a
simple C++ program
1. PRINTING STAR ’ * ‘ IN A-SHAPE
• Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n*2-2
4. If i+J=n-1 or J-i=n-1 or i=n/2 and i+J>n-1 and
J-i<2*n-1
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter Size:5
*
* *
* * * * *
* *
* *
{
for(int j=0;j<(n*2)-1;j++)
{
if((i+j==n-1)||(j-i==n-
1)||((i==n/2)&&((i+j>(n-1))&&(i+j<n*2-1))))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
• Code:
#include< iostream >
using namespace std;
int main()
{
int n;
cout<<"Enter Size:";
cin>>n;
if(n%2==0)
{
n=n+1;
}
for(int i=0;i<n;i++)
2.PRINTING STAR “*” IN B-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n*2+2
3. For J 0 to n+2
4. If J=0 or (J not equal to n+2 and i=0 or
i=n+1 or i=2*n+2) or (J=n+2 and i != 0 or i
!= n+1 or i != 2*n+2)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:3
* * * * *
* *
* *
* *
* * * * *
* *
* *
* *
* * * * *
Code
#include< iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for( int i=0;i<((n*2)+3);i++)
{
for( int j=0;j<n+3;j++)
{
if((j==0)||((j!=n+2)&&(i==0||i==n+1||i==n*2+2))||((j==n
+2)&&(i!=0&&i!=n+1&&i!=n*2+2)))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
3.PRINTING STAR “*” IN C-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or i=n-1 or J=0
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:4
* * * *
*
*
* * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==n-1||j==0)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
4.PRINTING STAR “*” IN D-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n*2+2
3. For J 0 to n+2
4. If J=1 or (J != n-1and i=0 or i=n-1) or (J=n-1
and i!=0 or i!=n-1)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * *
* *
* *
* *
* * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==1||(j!=n-1&&(i==0||i==n-1))||(j==n-
1&&(i!=0&&i!=n-1)))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
5.PRINTING STAR “*” IN E-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or i=n-1 or J=0 or i=n/2
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
* * * * *
*
* * * * *
if(j==0||i==0||i==n-1||i==n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
CODE
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
6.PRINTING STAR “*” IN F-
SHAPE
OUTPUT
Enter size:5
* * * * *
*
* * * * *
*
*
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or J=0 or i=n/2
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0||i==0||i==n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
7.PRINTING STAR “*” IN G-
SHAPE
OUTPUT
Enter size:5
* * * * *
*
* * * *
* *
* * * * *
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or J=0 or i=n-1 or (J=n-1 and
i>=n/2) or (i=n/2 and J>=n/2)
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0||i==0||i==n-1||(j==n-
1&&i>=n/2)||(i==n/2&&j>=n/2))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
8.PRINTING STAR “*” IN H-
SHAPE
OUTPUT
Enter size:5
* *
* *
* * * * *
* *
* *
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 or J=n-1 or i=n/2
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0||j==n-1||i==n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
9.PRINTING STAR “*” IN I-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or i=n-1 or J=n/2
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
*
*
* * * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==n-1||j==n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
10.PRINTING STAR “*” IN J-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n*2-1
4. If J=n-1 or (i=0 and J>n/2 and J<n*3/2) or
(i=n-1 and J<n-1) or ( J=0 and i>n/2)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
*
* *
* * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n*2;j++)
{
if(j==n-1||(i==0&&j>n/2&&j<n*3/2)||(i==n-
1&&j<n-1)||(j==0&&i>n/2))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
11.PRINTING STAR “*” IN K-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n*2-1
3. For J 0 to n
4. If i=0 or i+J=n or i-J=n
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:3
* *
* *
* *
*
* *
* *
* *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<=n*2;i++)
{
for(int j=0;j<=n;j++)
{
if(j==0||(i+j==n)||(i-j==n))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
12.PRINTING STAR “*” IN L-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 or i=n-1
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
*
*
*
*
* * * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0||i==n-1)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
13.PRINTING STAR “*” IN M-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 or J=n or (i=j or i+J=n and
i<=n/2)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* * * *
* * * *
* * *
* *
* *
* *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2!=0)
n=n+1;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
if(j==0||j==n||((i==j||(i+j==n))&&(i<=n/
2)))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
14.PRINTING STAR “*” IN N-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 or J=i or J=n-1
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* * *
* * *
* * *
* *
if(j==0||i==j||j==n-1)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
15.PRINTING STAR “*” IN O-
SHAPE
OUTPUT
Enter size:5
* * *
* *
* *
* *
* * *
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 and J!=0 and J!=n-1 or J=0 and i!=0 and
i!=n-1 or J=n-1 and i!=0 and i!=n-1 or i=n-1
and J!=0 and J!=n-1
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0&&j!=0&&j!=n-
1||j==0&&i!=0&&i!=n-1||j==n-
1&&i!=0&&i!=n-1||i==n-1&&j!=0&&j!=n-1)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
16.PRINTING STAR “*” IN P-
SHAPE
OUTPUT
Enter size:5
* * * *
* *
* *
* * * *
*
*
*
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n*2+2
3. For J 0 to n+2
4. If j=0 or (J!=n+2) and (i=0 or i=n+1) or
(J=n+2 and (i!=0 and i<n+1)
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<((n*2)+3);i++)
{
for(int j=0;j<n+3;j++)
{
if((j==0)||((j!=n+2)&&(i==0||i==n+1))||((
j==n+2)&&(i!=0&&i<n+1)))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
17.PRINTING STAR “*” IN Q-
SHAPE
OUTPUT
Enter size:5
* * *
* *
* *
* *
* * *
*
*
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n*2-1
3. For J 0 to n-1
4. If i=0 and J!=0 and J!=n-1 or J=0 and i!=0
and i<n-1 or J=n-1 and i!=0 and i<n-1 or
i=n-1 and J!=0 and J!=n-1 or i-J=n/2 and
i>=n
5. Print “*” star
6. Else Print “ “ space
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n*2;i++)
{
for(int j=0;j<n;j++)
{
if(i==0&&j!=0&&j!=n-1||j==0&&i!=0&&i<n-
1||j==n-1&&i!=0&&i<n-1||i==n-
1&&j!=0&&j!=n-1||i-j==n/2&&i>=n)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
18.PRINTING STAR “*” IN R-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 or (J!=n+2 and (i=0 or i=n+1)
or (J=n+2 and i!=0 and i<n+1) or
(i-J=n+1 and i>=n+2)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:2
* * * *
* *
* *
* * * *
* *
* *
* *
if((j==0)||((j!=n+2)&&(i==0||i==n+1))||((j==
n+2)&&(i!=0&&i<n+1))||(i-
j==n+1&&i>=n+2))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<((n*2)+3);i++)
{
for(int j=0;j<n+3;j++)
{
19.PRINTING STAR “*” IN S-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or i=n-1 or i=n/2 or (J=0 and i<n/2)
or (J=n-1 and i>n/2)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
* * * * *
*
* * * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==n-1||i==n/2||(j==0&&i<n/2)||(j==n-
1&&i>n/2))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
20.PRINTING STAR “*” IN T-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or J=n/2
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
*
*
*
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||j==n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
21.PRINTING STAR “*” IN U-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If J=0 and i!=n-1 or J=n-1 and
i!=n-1 or (i=n-1 and J!=0 and
J!=n-1)
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* *
* *
* *
* * *
if(j==0&&i!=n-1||j==n-1&&i!=n-
1||(i==n-1&&j!=0&&j!=n-1))
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
22.PRINTING STAR “*” IN V-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n*2-1
4. If i=J or i+J=2*n-2
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* *
* *
* *
*
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n*2;j++)
{
if(i==j||i+j==2*n-2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
23.PRINTING STAR “*” IN W-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n*4-1
4. If i=J or i+J=2*n-2 or J-i=2*n-2 or
i+J=4*n-4
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * *
* * * *
* * * *
* * * *
* *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<4*n;j++)
{
if(i==j||i+j==2*n-2||j-i==2*n-
2||i+j==4*n-4)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
24.PRINTING STAR “*” IN X-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=J or i+J=n-1
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* *
*
* *
* *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j||i+j==n-1)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
25.PRINTING STAR “*” IN Y-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=J and i<n/2 or i+J=n-1
and i<n/2 or J=n/2 and
i>=n/2
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* *
* *
*
*
*
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
if(n%2==0)
n=n+1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j&&i<n/2||i+j==n-
1&&i<n/2||j==n/2&&i>=n/2)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
26.PRINTING STAR “*” IN Z-
SHAPE
Algorithm
1. Let (row=i) and (column=J)
2. For i 0 to n-1
3. For J 0 to n-1
4. If i=0 or i=n-1 or i+J=n-1
5. Print “*” star
6. Else Print “ “ space
OUTPUT
Enter size:5
* * * * *
*
*
*
* * * * *
Code
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter size:";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==n-1||i+j==n-1)
{
cout<<"*";
}else{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}

C++ programming pattern

  • 1.
  • 2.
    1. INTRODUCTION • C++—thepopular and highly readable object-oriented Programming language—is both powerful and relatively easy to learn. Whether you're new to programming or an experienced developer, this course can help you get started with C++. Er. Raushan Kumar provides an overview of the Pattern program, basic Algorithm, and an example of how to construct and run a simple C++ program
  • 3.
    1. PRINTING STAR’ * ‘ IN A-SHAPE • Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n*2-2 4. If i+J=n-1 or J-i=n-1 or i=n/2 and i+J>n-1 and J-i<2*n-1 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter Size:5 * * * * * * * * * * * *
  • 4.
    { for(int j=0;j<(n*2)-1;j++) { if((i+j==n-1)||(j-i==n- 1)||((i==n/2)&&((i+j>(n-1))&&(i+j<n*2-1)))) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return0; } • Code: #include< iostream > using namespace std; int main() { int n; cout<<"Enter Size:"; cin>>n; if(n%2==0) { n=n+1; } for(int i=0;i<n;i++)
  • 5.
    2.PRINTING STAR “*”IN B- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n*2+2 3. For J 0 to n+2 4. If J=0 or (J not equal to n+2 and i=0 or i=n+1 or i=2*n+2) or (J=n+2 and i != 0 or i != n+1 or i != 2*n+2) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:3 * * * * * * * * * * * * * * * * * * * * * * * * * * *
  • 6.
    Code #include< iostream> using namespacestd; int main() { int n; cout<<"Enter size:"; cin>>n; for( int i=0;i<((n*2)+3);i++) { for( int j=0;j<n+3;j++) { if((j==0)||((j!=n+2)&&(i==0||i==n+1||i==n*2+2))||((j==n +2)&&(i!=0&&i!=n+1&&i!=n*2+2))) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 7.
    3.PRINTING STAR “*”IN C- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or i=n-1 or J=0 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:4 * * * * * * * * * *
  • 8.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0||i==n-1||j==0) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 9.
    4.PRINTING STAR “*”IN D- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n*2+2 3. For J 0 to n+2 4. If J=1 or (J != n-1and i=0 or i=n-1) or (J=n-1 and i!=0 or i!=n-1) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * * *
  • 10.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==1||(j!=n-1&&(i==0||i==n-1))||(j==n- 1&&(i!=0&&i!=n-1))) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 11.
    5.PRINTING STAR “*”IN E- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or i=n-1 or J=0 or i=n/2 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * * * * * *
  • 12.
    if(j==0||i==0||i==n-1||i==n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; } CODE #include<iostream> usingnamespace std; int main() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {
  • 13.
    6.PRINTING STAR “*”IN F- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or J=0 or i=n/2 5. Print “*” star 6. Else Print “ “ space
  • 14.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==0||i==0||i==n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 15.
    7.PRINTING STAR “*”IN G- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or J=0 or i=n-1 or (J=n-1 and i>=n/2) or (i=n/2 and J>=n/2) 5. Print “*” star 6. Else Print “ “ space
  • 16.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==0||i==0||i==n-1||(j==n- 1&&i>=n/2)||(i==n/2&&j>=n/2)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 17.
    8.PRINTING STAR “*”IN H- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 or J=n-1 or i=n/2 5. Print “*” star 6. Else Print “ “ space
  • 18.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==0||j==n-1||i==n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 19.
    9.PRINTING STAR “*”IN I- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or i=n-1 or J=n/2 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * *
  • 20.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0||i==n-1||j==n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 21.
    10.PRINTING STAR “*”IN J- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n*2-1 4. If J=n-1 or (i=0 and J>n/2 and J<n*3/2) or (i=n-1 and J<n-1) or ( J=0 and i>n/2) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * *
  • 22.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n*2;j++) { if(j==n-1||(i==0&&j>n/2&&j<n*3/2)||(i==n- 1&&j<n-1)||(j==0&&i>n/2)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 23.
    11.PRINTING STAR “*”IN K- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n*2-1 3. For J 0 to n 4. If i=0 or i+J=n or i-J=n 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:3 * * * * * * * * * * * * *
  • 24.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<=n*2;i++) { for(int j=0;j<=n;j++) { if(j==0||(i+j==n)||(i-j==n)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 25.
    12.PRINTING STAR “*”IN L- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 or i=n-1 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * *
  • 26.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j==0||i==n-1) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 27.
    13.PRINTING STAR “*”IN M- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 or J=n or (i=j or i+J=n and i<=n/2) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * * * * * * * *
  • 28.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2!=0) n=n+1; for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { if(j==0||j==n||((i==j||(i+j==n))&&(i<=n/ 2))) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 29.
    14.PRINTING STAR “*”IN N- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 or J=i or J=n-1 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * *
  • 30.
    if(j==0||i==j||j==n-1) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; } Code #include<iostream> usingnamespace std; int main() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {
  • 31.
    15.PRINTING STAR “*”IN O- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 and J!=0 and J!=n-1 or J=0 and i!=0 and i!=n-1 or J=n-1 and i!=0 and i!=n-1 or i=n-1 and J!=0 and J!=n-1 5. Print “*” star 6. Else Print “ “ space
  • 32.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0&&j!=0&&j!=n- 1||j==0&&i!=0&&i!=n-1||j==n- 1&&i!=0&&i!=n-1||i==n-1&&j!=0&&j!=n-1) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 33.
    16.PRINTING STAR “*”IN P- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n*2+2 3. For J 0 to n+2 4. If j=0 or (J!=n+2) and (i=0 or i=n+1) or (J=n+2 and (i!=0 and i<n+1) 5. Print “*” star 6. Else Print “ “ space
  • 34.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<((n*2)+3);i++) { for(int j=0;j<n+3;j++) { if((j==0)||((j!=n+2)&&(i==0||i==n+1))||(( j==n+2)&&(i!=0&&i<n+1))) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 35.
    17.PRINTING STAR “*”IN Q- SHAPE OUTPUT Enter size:5 * * * * * * * * * * * * * * Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n*2-1 3. For J 0 to n-1 4. If i=0 and J!=0 and J!=n-1 or J=0 and i!=0 and i<n-1 or J=n-1 and i!=0 and i<n-1 or i=n-1 and J!=0 and J!=n-1 or i-J=n/2 and i>=n 5. Print “*” star 6. Else Print “ “ space
  • 36.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n*2;i++) { for(int j=0;j<n;j++) { if(i==0&&j!=0&&j!=n-1||j==0&&i!=0&&i<n- 1||j==n-1&&i!=0&&i<n-1||i==n- 1&&j!=0&&j!=n-1||i-j==n/2&&i>=n) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 37.
    18.PRINTING STAR “*”IN R- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 or (J!=n+2 and (i=0 or i=n+1) or (J=n+2 and i!=0 and i<n+1) or (i-J=n+1 and i>=n+2) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:2 * * * * * * * * * * * * * * * * * *
  • 38.
    if((j==0)||((j!=n+2)&&(i==0||i==n+1))||((j== n+2)&&(i!=0&&i<n+1))||(i- j==n+1&&i>=n+2)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; } Code #include<iostream> usingnamespace std; int main() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<((n*2)+3);i++) { for(int j=0;j<n+3;j++) {
  • 39.
    19.PRINTING STAR “*”IN S- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or i=n-1 or i=n/2 or (J=0 and i<n/2) or (J=n-1 and i>n/2) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * * * * * *
  • 40.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0||i==n-1||i==n/2||(j==0&&i<n/2)||(j==n- 1&&i>n/2)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 41.
    20.PRINTING STAR “*”IN T- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or J=n/2 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * *
  • 42.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0||j==n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 43.
    21.PRINTING STAR “*”IN U- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If J=0 and i!=n-1 or J=n-1 and i!=n-1 or (i=n-1 and J!=0 and J!=n-1) 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * *
  • 44.
    if(j==0&&i!=n-1||j==n-1&&i!=n- 1||(i==n-1&&j!=0&&j!=n-1)) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; } Code #include<iostream> usingnamespace std; int main() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) {
  • 45.
    22.PRINTING STAR “*”IN V- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n*2-1 4. If i=J or i+J=2*n-2 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * *
  • 46.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n*2;j++) { if(i==j||i+j==2*n-2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 47.
    23.PRINTING STAR “*”IN W- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n*4-1 4. If i=J or i+J=2*n-2 or J-i=2*n-2 or i+J=4*n-4 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * * * * * *
  • 48.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<4*n;j++) { if(i==j||i+j==2*n-2||j-i==2*n- 2||i+j==4*n-4) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 49.
    24.PRINTING STAR “*”IN X- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=J or i+J=n-1 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * *
  • 50.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j||i+j==n-1) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 51.
    25.PRINTING STAR “*”IN Y- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=J and i<n/2 or i+J=n-1 and i<n/2 or J=n/2 and i>=n/2 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * *
  • 52.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; if(n%2==0) n=n+1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j&&i<n/2||i+j==n- 1&&i<n/2||j==n/2&&i>=n/2) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }
  • 53.
    26.PRINTING STAR “*”IN Z- SHAPE Algorithm 1. Let (row=i) and (column=J) 2. For i 0 to n-1 3. For J 0 to n-1 4. If i=0 or i=n-1 or i+J=n-1 5. Print “*” star 6. Else Print “ “ space OUTPUT Enter size:5 * * * * * * * * * * * * *
  • 54.
    Code #include<iostream> using namespace std; intmain() { int n; cout<<"Enter size:"; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==0||i==n-1||i+j==n-1) { cout<<"*"; }else{ cout<<" "; } } cout<<endl; } return 0; }