Write a program that can create 4 different patterns of varying sizes. The size
ID: 3758263 • Letter: W
Question
Write a program that can create 4 different patterns of varying sizes. The size of each pattern is determined by the number of columns or rows. For example, a pattern of size 5 has 5 columns and 5 rows. Each pattern is made of the character * and a digit, which shows the size. The size must be between 5 and 10.
Explanation / Answer
#include void showmenu(); double Get_option (); double Get_size (); void pattern1 (int); void pattern2 (int); void pattern3 (int); void pattern4 (int); int main () { int size1, option1; const int pattern_1 = 1, pattern_2 = 2, pattern_3 = 3, pattern_4 = 4, quit = 5; do { showmenu (); option1 = Get_option (); size1 = Get_size (); if (option1 != quit) { switch (option1) { case 1: pattern1 (size1); break; case 2: pattern2 (size1); break; case 3: pattern3 (size1); break; case 4: pattern4 (size1); break; case 5: exit (1); break; } } } while (option1 != quit); return 0; } void showmenu () { printf (" MENU " ); printf ( "1. Pattern One" ); printf ( "2. Pattern Two" ); printf ( "3. Pattern Three" ); printf ( "4. Pattern Four" ); printf ( "Quit " ); } double Get_option () { int option; printf ("enter option (1-5):"); scanf ("%d", &option); while (option < 1 || option > 5) { printf ("incorrect option. Try again"); printf ("Enter option (1-5):"); scanf ("%d", &option); } return option; } double Get_size () { int size; printf ("Enter pattern size (2-9):"); scanf ("%d", &size); while (size < 2 || size > 9); { printf ("Incorrect pattern size. Try again"); printf ("Enter pattern size (2-9):"); scanf ("%d", &size); } return size; } void pattern1 (int size1) { int row, col; for (row = 0; rowRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.