Write a C++ program to print a rhombus or parallelogram star pattern.
Flowchart to print a rhombus or parallelogram star pattern
C++ program (source code) to print a parallelogram or rhombus star pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include<iostream> using namespace std; int main() { int i=1,j,k,n; do { j=i; do { cout<<" "; j++; } while(j<=5); k=1; do { cout<<"*"; k++; } while(k<=5); i++; cout<<endl; } while(i<=5); } |
Output
Excercise
Find the possible mistakes in the following Shamil’s Flow Table of the program to print a rhombus or parallelogram star pattern.
Loop i | Loop j | Loop k | Actual work to do |
I = 1 | J=1
J=2 J=3 J=4 J=5 |
K=1
K=2 K=3 K=4 K=5 |
1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 11, 12, 13, 14)5, 15, 16, (17, 18, 19, 20, 21, 22)5, 23,
24, 25, 26, 27 |
I = 2 | J=1
J=2 J=3 J=4 |
K=1
K=2 K=3 K=4 K=5 |
1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 11, 12, 13, 14)5, 15, 16, (17, 18, 19, 20, 21, 22)5, 23,
24, 25, 26,6,7,(8,9,10,11,12,13,14)4,15,16,(17,18,19,20,21,22)5,23, 24, 25, 26, 27 |
I = 3 | J=1
J=2 J=3
|
K=1
K=2 K=3 K=4 K=5 |
1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 11, 12, 13, 14)5, 15, 16, (17, 18, 19, 20, 21, 22)5, 23,
24, 25, 26, 6,7,(8,9,10,11,12,13,14)4,15,16,(17,18,19,20,21,22)5,23, 24,25,26, 6,7,(8,9,10,11,12,13,14)3,15,16,(17,18,19,20,21,22)5,23, 24, 25, 26, 27 |
I = 4 | J=1
J=2
|
K=1
K=2 K=3 K=4 K=5 |
1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 11, 12, 13, 14)5, 15, 16, (17, 18, 19, 20, 21, 22)5, 23,
24, 25, 26, 6,7,(8,9,10,11,12,13,14)4,15,16,(17,18,19,20,21,22)5,23,24,25,26, 6,7,(8,9,10,11,12,13,14)3,15,16,(17,18,19,20,21,22)5,23, 24,25,26, 6,7,(8,9,10,11,12,13,14)2,15,16,(17,18,19,20,21,22)5,23, 24, 25, 26, 27 |
I = 4 | J=1
|
K=1
K=2 K=3 K=4 K=5 |
1, 2, 3, 4, 5, 6, 7, (8, 9, 10, 11, 12, 13, 14)5, 15, 16, (17, 18, 19, 20, 21, 22)5, 23,
24, 25, 26, 6,7,(8,9,10,11,12,13,14)4,15,16,(17,18,19,20,21,22)5,23, 24,25,26, 6,7,(8,9,10,11,12,13,14)3,15,16,(17,18,19,20,21,22)5,23, 24,25,26, 6,7,(8,9,10,11,12,13,14)2,15,16,(17,18,19,20,21,22)5,23, 24,25,26,27, 6,7,8,9,10,11,12,13,14,15,16,(17,18,19,20,21,22)5,23, 24, 25, 26, 27 |