Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this lab, you are going to be writing and calling your own functions instead

ID: 3785531 • Letter: F

Question

For this lab, you are going to be writing and calling your own functions instead of those which were written for you by someone else (e.g. printf, scanf). A key element in understanding all this is to remember that a function does not run until it is called, and that it runs once for every time it’s called, and it can be called as many times as you like in the program. (All your programs so far have called printf many times.) For this project you are to write three functions, write_G(), write_U(), and write_O(). Write_G does something like this: XXXXXXXXX XX XX XX XX XX XX XXXX XX XX XX XX XXXXXXXXX The write_U and the write_O do the same kind of thing, but make different letters. When you write your own functions, you begin by putting a prototype for each function below the #include(s) but above the int main. This would look something like void write_G(); Then, below the main you write the function definition, which in this case uses printf’s to write each of the block letters that we need. (I showed a block G. You can figure out a block U and a block O.) Now your main function is going to be very short. It should call each of the functions in such an order as to vertically write the U G G O Notice that you do not have to have two copies of the write_G function. All you need is to call the G twice and you will see two G’s.

How do I write this?

Explanation / Answer

#include <stdio.h>
void Write_G();
void Write_U();
void Write_O();

int main(void) {
   Write_U();
   Write_G();
   Write_G();
   Write_O();
   return 0;
}

void Write_G()
{
   int i,j;
  
   for(i = 0; i < 9; i++)
   {
       printf("X");
   }
   printf(" ");
   for(j = 0; j < 6; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("X");
       }
       printf(" ");
   }
  
  
   for(i = 0; i < 4; i++)
   {
       printf("X");
   }
   printf(" ");
  
   for(j = 0; j < 4; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("X");
       }
       printf(" ");
   }
   for(i = 0; i < 9; i++)
   {
       printf("X");
   }
   printf(" ");
}


void Write_U()
{
   int i,j;
   for(i = 0; i < 9; i++)
   {
       printf("Y");
   }
   printf(" ");
   for(j = 0; j < 6; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("Y");
       }
       printf(" ");
   }
  
  
   for(i = 0; i < 4; i++)
   {
       printf("Y");
   }
   printf(" ");
  
   for(j = 0; j < 4; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("Y");
       }
       printf(" ");
   }
   for(i = 0; i < 9; i++)
   {
       printf("Y");
   }
   printf(" ");
}

void Write_O()
{
   int i,j;
   for(i = 0; i < 9; i++)
   {
       printf("Z");
   }
   printf(" ");
   for(j = 0; j < 6; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("Z");
       }
       printf(" ");
   }
  
  
   for(i = 0; i < 4; i++)
   {
       printf("Z");
   }
   printf(" ");
  
   for(j = 0; j < 4; j++)
   {
       for(i =0; i < 2; i++)
       {
           printf("Z");
       }
       printf(" ");
   }
   for(i = 0; i < 9; i++)
   {
       printf("Z");
   }
   printf(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote