Write a C program to maintain a record of “n” student details using an array of
structures with four fields (Roll number, Name, Marks, and Grade). Each field is of
an appropriate data type. Print the marks of the student given student name as
input
Answer:
Structure is collection of different data type. An object of structure represents a single
record in memory, if there are more than one record of structure type, there is a need to
create an array of structure or object.
ALGORITHM:
When all the details are entered it is stored in an array of structures. The marks of student is used to
process the grades and stored in the variable grade of each students.
INPUT
Name
Roll No
Marks
Grade
Ouput: Print Mark of the searched student
Step1: Create a structure student to maintain a details like Name, Roll No, Marks of the
student
Step 2: Getting N number of student records to maintain
Step3: The details are entered it is stored in an array of structures.
Step3: Search the student in the record to get the mark.
Step4: Print the student Name and his respective Mark
Step5: If student Name not find in the record print Detailed Not found
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
char name[20];
int rollNo;
int marks[3];
float percentage;
};
int main(){
struct student *stuArray;
int n,i,j;
int tempTotal=0,flag=0,foundIndex;
char tempName[14];
printf("\n Enter N number of student records to maintain :: ");
scanf("%d",&n);
stuArray = (struct student*)malloc(n*sizeof(struct student));
for(i=0;i<n;i++){
printf("\n %[Link] :",(i+1));
scanf("%s",&stuArray[i].name);
printf("\n Roll Number :",(i+1));
scanf("%d",&stuArray[i].rollNo);
tempTotal=0;
for(j=0;j<3;j++)
printf("\n Mark %d :",(j+1));
scanf("%d",&stuArray[i].marks[j]);
tempTotal+=stuArray[i].marks[j];
stuArray[i].percentage=tempTotal/3;
printf("\n Enter the student Name to be Searched and print the mark of the student: ");
scanf("%s",&tempName);
for(i=0;i<n;i++){
if(strcmp(tempName,stuArray[i].name)==0)
foundIndex=i;
flag=1;
break;
if(flag==0)
printf("Details Not Found");
else
printf("\n Mark of %s are given below...",tempName);
for(i=0;i<3;i++)
printf("\n Mark %d is %d",(i+1),stuArray[foundIndex].marks[i]);
}
return 0;
OUTPUT:
Enter N number of student records to maintain :: 1
[Link] :Priyanka
Roll Number :2019188042
Mark 1 :87
Mark 2 :98
Mark 3 : 89
Enter the student Name to be searched and print the mark of the student: Priyanka
Mark of Priyanka are given below...
Mark 1 is 87
Mark 2 is 98
Mark 3 is 89