-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumeric_pyramid.c
55 lines (45 loc) · 1.46 KB
/
numeric_pyramid.c
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
#include <stdio.h>
int main(void)
{
int r, c, rows;
char choice = 'y';
do {
// Get user input for number of rows
printf("\nEnter the number of rows for the pyramid (1-25): ");
if (scanf("%d", &rows) != 1) {
printf("\nInvalid input. Please enter a number.\n");
// Clear input buffer
while (getchar() != '\n');
continue;
}
// Validate input
if (rows < 1 || rows > 25) {
printf("\nNumber of rows should be between 1 and 25.\n");
// Clear input buffer
while (getchar() != '\n');
continue;
}
// Clear input buffer
while (getchar() != '\n');
// Print the pattern
printf("\nNumeric Pyramid Pattern:\n\n");
for (r = 1; r <= rows; r++)
{
for (c = 1; c <= r; c++)
{
if (r == rows || c == 1 || c == r)
printf("%2d ", c);
else
printf(" ");
}
printf("\n");
}
// Ask user if they want to continue
printf("\nDo you want to print another pattern? (y/n): ");
scanf(" %c", &choice);
// Clear input buffer
while (getchar() != '\n');
} while (choice == 'y' || choice == 'Y');
printf("\nThank you for using the pattern printer. Goodbye!\n\n");
return 0;
}