In: Computer Science
Create a structure In C program named Student
with the following components and appropriate data types:
Name,
ID, CGPA
i. Create an Array of Students of size three and take user input to
fill the array.
ii. Now find the student with the least CGPA and display his or
hers Name, ID and CGPA.
C code:
#include <stdio.h>
struct student
{
char name[50];
int id;
float cgpa;
} s[3];
int main()
{
int i;
printf("Enter students Name,Id,Cgpa:\n");
for(i=0; i<3; ++i)
{
printf("Enter student's name: ");
scanf("%s",s[i].name);
printf("Enter student's Id: ");
scanf("%d",&s[i].id);
printf("Enter Cgpa of student: ");
scanf("%f",&s[i].cgpa);
}
printf("Displaying student Info with Least Cgpa:\n");
struct student temp;
temp = s[0];
for(i=1; i<3; ++i)
{
if(s[i].cgpa < temp.cgpa)
temp = s[i];
}
printf("Student Name :%s\nStudentId: %d\nStudent Cgpa:
%f",temp.name,temp.id,temp.cgpa);
return 0;
}
Execution screenshot:
Note:please like the answer.Thank you.Have a nice day.