Problem 53

author
By Supreme2023-03-16
Problem Statement :
Design a structure student_record to contain name, branch and total marks obtained. Develop a program to read data for 10 students in a class and print them.
Code:

#include <stdio.h>

struct student_record {
char name[50];
char branch[50];
int total_marks;
};

int main() {

/*53. Design a structure student_record to contain name, branch and total marks obtained.
Develop a program to read data for 10 students in a class and print them.*/

struct student_record student[10];
int i;

printf("\tStudent Details\n");
printf("==========================================");

for (i = 0; i < 10; i++) {
printf("\n\nEnter Name For Student %d: ", i+1);
scanf("%s", student[i].name);
printf("\nEnter Branch For Student %d: ", i+1);
scanf("%s", student[i].branch);
printf("\nEnter Total Marks For Student %d: ", i+1);
scanf("%d", &student[i].total_marks);
}

printf("\nStudent Records:\n");
for (i = 0; i < 10; i++) {
printf("\nName: %s\n", student[i].name);
printf("Branch: %s\n", student[i].branch);
printf("Total Marks: %d\n", student[i].total_marks);
printf("\n");
}

return 0;
}

Description :
  • This program is designed to read and display the data of 10 students using a structure called student_record.
  • The program starts by defining the student_record structure that contains three members - name, branch, and total_marks - to hold the information for each student.
  • In the main() function, an array of 10 student_record structures is declared.
  • The program then prompts the user to enter the details for each student using a for loop. The details include the student's name, branch, and total marks.
  • The program reads the input values using scanf() function and stores them in the corresponding member variables of the student_record structure.
  • After all the data has been read and stored in the array of structures, the program then prints the student details using another for loop.
  • The program uses printf() function to display the student's name, branch, and total marks in a formatted manner.
  • Finally, the program returns 0 to indicate successful completion.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.