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

C PROGRAMMING C PROGRAMMING 2 of 4 Laboratory Exercises 1. Practice with functio

ID: 3812235 • Letter: C

Question

C PROGRAMMING

C PROGRAMMING

2 of 4 Laboratory Exercises 1. Practice with functions that do not pass any arguments 1.1 Write a program named "my initials.c' at prints your first and last initials (using the letters to form the characters) in the order selected by the user. So, if your first and last initials are, JF, and the user selects the order, first ast, your program would print JJ FF Your program must call two functions: one that prints out your first initial, and a second function that prints out your last initial. Your program does not need to request from the user arbitrary character input defining the initials (in other words, you can 'hard code' in the print statements for your particular in but it needs to get input from the user to determine the order that the two characters are printed. Include your code and evidence that it works in your report. A suggested strategy for developing your program is to first develop the printfo statement(s) that prints your first initial and another that prints your last initial. These will form the core of the two functions your program will call. Once you are satisfied that the lines of code for printing the initials are satisfactory, incorporate them into two functions. Include pseudocode or a flowchart to show the logic of your program in your report. It may help to use grid paper to figure out how to amange the printing ofthe characters to fom the letters. 2. Practice with functions that pass arguments 137.61% v

Explanation / Answer

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

void printInitials(int val1)
{
   if (val1 == 1)
   {
       printf(" J ");
       printf(" J ");
       printf(" J J ");
       printf(" JJ ");
       printf(" ");
       printf("FFFF ");
       printf("F ");
       printf("FF ");
       printf("F ");
       printf(" ");
   }
   else if (val1 == 2)
   {
       printf("FFFF ");
       printf("F ");
       printf("FF ");
       printf("F ");
       printf(" ");

       printf(" J ");
       printf(" J ");
       printf(" J J ");
       printf(" JJ ");
   }

}
void printFirstInitial()
{
   printf(" J ");
   printf(" J ");
   printf(" J J ");
   printf(" JJ ");

}

void printLastInitial()
{
   printf("FFFF ");
   printf("F ");
   printf("FF ");
   printf("F ");
   printf(" ");
}


int main()
{
   printFirstInitial();
   printLastInitial();

   printLastInitial();
   printFirstInitial();

   printInitials(1);
   printInitials(2);

   return 0;
}