forked from harshilp24/Hacktoberfest_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu driven pattern program
84 lines (77 loc) · 1.2 KB
/
Menu driven pattern program
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream.h>
#include<conio.h>
#include<process.h>
void ltrsPtrn(int n)
{
int i, j;
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
cout<<char(65+j);
}
cout<<'\n';
}
}
void dgtsPtrn(int n)
{
int i, j;
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
cout<<j+1;
}
cout<<'\n';
}
}
void starPtrn(int n)
{
int i, j;
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
cout<<'*';
}
cout<<'\n';
}
}
void rvrsPtrn(int n)
{
int i, j;
for(i=0; i<n; i++)
{
for(j=n-i; j>0; j--)
{
cout<<'*';
}
cout<<'\n';
}
}
void main()
{
clrscr();
int n, r;
char ch;
cout<<"Enter a number. ";
cin>>r;
do
{
cout<<"\n\tMenu.";
cout<<"\n1. Alphabetical Pattern\n2. Digits Pattern\n3. Star Pattern\n4. Reverse star Pattern\n5. Exit.\nEnter your choice. ";
cin>>n;
switch(n)
{
case 1: ltrsPtrn(r); break;
case 2: dgtsPtrn(r); break;
case 3: starPtrn(r); break;
case 4: rvrsPtrn(r); break;
case 5: exit(0); break;
default: cout<<"\nPlease enter valid choice {1-5}!";
}
cout<<"Want to run again? (Yes/No)";
cin>>ch;
} while( (ch=='Y') || (ch=='y') );
getch();
}