Student Highest Marks File Handling coderinme

Student Highest Marks File Handling coderinme

Student Highest Marks File Handling coderinme
The annual examination results of 100 students are tabulated in a file as follows: Roll No, Subject 1, Subject 2, Subject 3. Write a program to read the data and determine the following:
a) Total marks obtained by each student
b) The highest marks in each subject and the roll no. of the student who secured it
c) Roll no. of first three position holders.

#include<stdio.h>
#include<string.h>
struct stud
{
int roll,sum;
int s1,s2,s3;
} a[100];
int main()
{
FILE *inpt;
int i = 0,temp,temp1,temp2,temp3,temp4,temp5,d;
int max1 = 0,max3 = 0,max2 = 0,max6 = 0,max4 = 0,max5 = 0;
inpt = fopen("student.txt","r");
printf("Roll no.\tMarks\n");
while(!feof(inpt))
{
fscanf(inpt,"%d %d %d %d",&a[i].roll,&a[i].s1,&a[i].s2,&a[i].s3);
a[i].sum=a[i].s1+a[i].s2+a[i].s3;
printf("%d\t%d\n",a[i].roll,a[i].sum);
if(max1<a[i].s1)
{
max1=a[i].s1;
temp=a[i].roll;
}
if(max2<a[i].s2)
{
max2=a[i].s2;
temp1=a[i].roll;
}
if(max3<a[i].s3)
{
max3=a[i].s3;
temp2=a[i].roll;
}
i++;
}
d=i;
for(i=0;i<=d;i++)
{
if(max4<a[i].sum)
{
max4=a[i].sum;
temp3=a[i].roll;
printf("\n%d",max5);
}
}
for(i=0;i<=d;i++)
{
if(max5<a[i].sum)
{
if(a[i].sum==max4);
else
{
max5=a[i].sum;
temp4=a[i].roll;
}
}
}
for(i=0;i<=d;i++)
{
if(max6==max4||max6==max5||max6<a[i].sum)
{
if(a[i].sum==max4 ||a[i].sum==max5);
else
{
max6=a[i].sum;
temp5=a[i].roll;
}
}
}
i=d;
printf("\nMAXIMUM MARKS SUBJECT WISE:");
printf("subject1:Roll No.%d marks %d\n",temp,max1);
printf("subject2:Roll No.%d marks %d\n",temp1,max2);
printf("subject3:Roll No.%d marks %d\n",temp2,max3);
printf("\nPOSITION WISE:");
printf("\n1:Roll No.%d marks %d\n",temp3,max4);
printf("2:Roll No.%d marks %d\n",temp4,max5);
printf("3:Roll No.%d marks %d\n",temp5,max6);
fclose(inpt);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Student Highest Marks File Handling coderinme

Student Highest Marks File Handling coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.