183k views
5 votes
Question 1: Write a C function that declares a student structure that contains his name, his first name and his student number.

Question 2: Write a C function that initializes the cell by taking the 3 parameters from the keyboard.

Question 3: Write a function that displays the contents of the cell passed as a parameter.

User Seether
by
7.2k points

1 Answer

6 votes

Final answer:

To declare a student structure in C that contains name, first name, and student number, you can use the 'struct' keyword. To initialize the cell and display its contents, use the 'scanf' function to read input values into the structure variables and the 'printf' function to display the values.

Step-by-step explanation:

Question 1:

To declare a student structure in C that contains his name, first name, and student number, you can use the following code:

struct Student {
char name[50];
char firstName[50];
int studentNumber;
};



Question 2:

To initialize the cell by taking the three parameters from the keyboard, you can use the scanf function to read input values into the structure variables. Here's an example:

void initializeStudent(struct Student *s) {
printf("Enter name: ");
scanf("%s", s->name);
printf("Enter first name: ");
scanf("%s", s->firstName);
printf("Enter student number: ");
scanf("%d", &s->studentNumber);
}



Question 3:

To display the contents of the cell passed as a parameter, you can use the following function:

void displayStudent(struct Student s) {
printf("Name: %s\\", s.name);
printf("First Name: %s\\", s.firstName);
printf("Student Number: %d\\", s.studentNumber);
}
User TurboFish
by
8.0k points