Highest total marks holder using Structure
#include<stdio.h>
#include<conio.h>
struct Student
{
int roll;
char name[25];
char addr[25];
int mark[5];
int total;
float avg;
char grad;
};
int checkHighest(struct Student [],int);
void getVal(struct Student [],int);
void printDetail(struct Student [],int);
int main()
{
struct Student std[50];
int m,t,i;
printf("\nEnter the number of students :");
scanf("%d",&m);
printf("\nEnter the student details : ");
getVal(std,m);
printf("\nStudent details : ");
for(i=0;i<m;i++)
{
printf("\n\n\n=================================================");
printDetail(std,i);
printf("\n=================================================");
}
printf("\nHighest Marks holder is : ");
t=checkHighest(std,m);
printDetail(std,t);
system("pause");
}
void getVal(struct Student st[],int p)
{
int i,j,s;
for(i=0;i<p;i++)
{
printf("\nEnter the roll number: ");
scanf("%d",&st[i].roll);
fflush(stdin);
printf("\nEnter the name : ");
gets(st[i].name);
fflush(stdin);
printf("\nEnter the address : ");
gets(st[i].addr);
printf("\nEnter the marks for 5 subjects : ");
s=0;
for(j=0;j<5;j++)
{
printf("\nEnter subject %d :",j+1);
scanf("%d",&st[i].mark[j]);
s=s+st[i].mark[j];
}
st[i].total=s;
st[i].avg=s/5;
if(st[i].avg>=90)
st[i].grad='O';
else if(st[i].avg>=80)
st[i].grad='E';
else if(st[i].avg>=70)
st[i].grad='A';
else if(st[i].avg>=60)
st[i].grad='B';
else if(st[i].avg>=50)
st[i].grad='C';
else if(st[i].avg>=40)
st[i].grad='D';
else
st[i].grad='F';
}
}
int checkHighest(struct Student st[],int p)
{
int i,max,t=0;
max=st[0].total;
for(i=1;i<p;i++)
{
if(st[i].total>max)
{
max=st[i].total;
t=i;
}
}
return t;
}
void printDetail(struct Student st[],int j)
{
printf("\nRoll Number : %d",st[j].roll);
printf("\nName : ");
puts(st[j].name);
printf("\nAddress : ");
puts(st[j].addr);
printf("\nTotal : %d",st[j].total);
printf("\nGrade : %c",st[j].grad);
}
#include<conio.h>
struct Student
{
int roll;
char name[25];
char addr[25];
int mark[5];
int total;
float avg;
char grad;
};
int checkHighest(struct Student [],int);
void getVal(struct Student [],int);
void printDetail(struct Student [],int);
int main()
{
struct Student std[50];
int m,t,i;
printf("\nEnter the number of students :");
scanf("%d",&m);
printf("\nEnter the student details : ");
getVal(std,m);
printf("\nStudent details : ");
for(i=0;i<m;i++)
{
printf("\n\n\n=================================================");
printDetail(std,i);
printf("\n=================================================");
}
printf("\nHighest Marks holder is : ");
t=checkHighest(std,m);
printDetail(std,t);
system("pause");
}
void getVal(struct Student st[],int p)
{
int i,j,s;
for(i=0;i<p;i++)
{
printf("\nEnter the roll number: ");
scanf("%d",&st[i].roll);
fflush(stdin);
printf("\nEnter the name : ");
gets(st[i].name);
fflush(stdin);
printf("\nEnter the address : ");
gets(st[i].addr);
printf("\nEnter the marks for 5 subjects : ");
s=0;
for(j=0;j<5;j++)
{
printf("\nEnter subject %d :",j+1);
scanf("%d",&st[i].mark[j]);
s=s+st[i].mark[j];
}
st[i].total=s;
st[i].avg=s/5;
if(st[i].avg>=90)
st[i].grad='O';
else if(st[i].avg>=80)
st[i].grad='E';
else if(st[i].avg>=70)
st[i].grad='A';
else if(st[i].avg>=60)
st[i].grad='B';
else if(st[i].avg>=50)
st[i].grad='C';
else if(st[i].avg>=40)
st[i].grad='D';
else
st[i].grad='F';
}
}
int checkHighest(struct Student st[],int p)
{
int i,max,t=0;
max=st[0].total;
for(i=1;i<p;i++)
{
if(st[i].total>max)
{
max=st[i].total;
t=i;
}
}
return t;
}
void printDetail(struct Student st[],int j)
{
printf("\nRoll Number : %d",st[j].roll);
printf("\nName : ");
puts(st[j].name);
printf("\nAddress : ");
puts(st[j].addr);
printf("\nTotal : %d",st[j].total);
printf("\nGrade : %c",st[j].grad);
}
I/O: It will take details of several students and find out the details of maximum total marks holder .....
Comments
Post a Comment