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

Programming in C exercise, does not have to be entire program, just the struct q

ID: 3828786 • Letter: P

Question

Programming in C exercise, does not have to be entire program, just the struct questions

1. Write a preprocessor directive to set the constant NUM to a value large enough for the follow question.

2. Define a struct called teacher with the following fields:

--- A character array for the last name

--- A character for the first initial

--- A character array for the subject

--- An integer for the age

3. Declare a single (not an array) variable with the data type teacher and, using keyboard input, initialize all data fields of your structure variable.

Explanation / Answer

Please let me know in case of any issue.


#define NUM 30

struct teacher{
   char lastName[NUM];
   char firstName[NUM];
   char subject[NUM];
   int age;
};

int main(){

   struct teacher teacher1;

   printf("Enter last name: ");
   gets(teacher1.lastName);

   printf("Enter first name: ");
   gets(teacher1.firstName);

   printf("Enter subject: ");
   gets(teacher1.subject);

   printf("Enter age: ");
   scanf("%d", &(teacher1.age));

   return 0;
}