Highest marks in a particular subject 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;
};
void getVal(struct Student [],int);
void printDetail(struct Student [],int);
int checkSubHighest(struct Student [],int,int);
int main()
{
struct Student std[50];
int m,t,i,p;
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("\nEnter the subject number for which u want to find out the highest marks holder : ");
scanf("%d",&p);
t=checkSubHighest(std,m,p);
printf("\nHighest Marks holder is : ");
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';
}
}
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\n",st[j].grad);
}
int checkSubHighest(struct Student st[],int p,int t)
{
int max,i,m=0;
max=st[0].mark[t];
for(i=1;i<p;i++)
{
if(st[i].mark[t]>max)
{
max=st[i].mark[t];
m=i;
}
}
return m;
}
I/O : It will take details of several students and find out the detail of the student got highest marks in particular subject .........
#include<conio.h>
struct Student
{
int roll;
char name[25];
char addr[25];
int mark[5];
int total;
float avg;
char grad;
};
void getVal(struct Student [],int);
void printDetail(struct Student [],int);
int checkSubHighest(struct Student [],int,int);
int main()
{
struct Student std[50];
int m,t,i,p;
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("\nEnter the subject number for which u want to find out the highest marks holder : ");
scanf("%d",&p);
t=checkSubHighest(std,m,p);
printf("\nHighest Marks holder is : ");
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';
}
}
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\n",st[j].grad);
}
int checkSubHighest(struct Student st[],int p,int t)
{
int max,i,m=0;
max=st[0].mark[t];
for(i=1;i<p;i++)
{
if(st[i].mark[t]>max)
{
max=st[i].mark[t];
m=i;
}
}
return m;
}
I/O : It will take details of several students and find out the detail of the student got highest marks in particular subject .........
Comments
Post a Comment