p1 by ma'am

// 1.Write a program to calculate student result for three subjects for float three subject for four students. Find student having highest score in each subject, also student who is first in class.
#include <stdio.h>
#include <conio.h>
void clas(float);
struct stud
{
int rno;
int sub[3];
int tot;
float per;
};
void main()
{
int i, j;
int r, s1, s2, s3, t, x;
char a[20];
struct stud s[3];
clrscr();
// Scanning The Students Detail;
for (i = 0; i < 3; i++)
{
s[i].tot = 0;
s[i].per = 0;
printf("\nRoll No:- ");
scanf("%d", &s[i].rno);
for (j = 0; j < 3; j++)
{
printf(" Enter Mark of Sub %d:- ", j + 1);
scanf("%d", &s[i].sub[j]);
s[i].tot = s[i].tot + s[i].sub[j];
s[i].per = (s[i].tot / 3);
}
}
// Sorting In Descending Order;
for (i = 0; i < 3; i++)
{
for (j = i + 1; j < 3; j++)
{
if (s[i].tot < s[j].tot)
{
r = s[i].rno;
s1 = s[i].sub[0];
s2 = s[i].sub[1];
s3 = s[i].sub[2];
t = s[i].tot;
x = s[i].per;
s[i].rno = s[j].rno;
s[i].sub[0] = s[j].sub[0];
s[i].sub[1] = s[j].sub[1];
s[i].sub[2] = s[j].sub[2];
s[i].tot = s[j].tot;
s[i].per = s[j].per;
s[j].rno = r;
s[j].sub[0] = s1;
s[j].sub[1] = s2;
s[j].sub[2] = s3;
s[j].tot = t;
s[j].per = x;
}
}
}
// Print The Result;
clrscr();
printf("\t\twww.Engiguide.com\n");
for (i = 0; i < 3; i++)
{
printf("-------------------------------------------------------------------------------");
printf("\nRank Roll no Sub 1 Sub 2 Sub 3 Total Percentage class");
printf("\n----------------------------------------------------------------------------");
for (i = 0; i < 3; i++)
{
printf("\n%2d %2d %2d %2d %2d %3d %.2f% ",i+1,s[i].rno,s[i].sub[0],s[i].sub[1],s[i].sub[2],s[i].tot,s[i].per);
clas(s[i].per);
}
printf("\n--------------------------------------------------------------------------------");
}
getch();
}
// function Body To Check Class
void clas(float p)
{
if (p >= 60 && p < 70)
printf("First Class");
else if (p >= 70)
printf("Distinction");
else if (p >= 40 && p < 48)
printf("Pass Class");
else if (p >= 48 && p < 60)
printf("Second class");
else if (p < 40)
printf("Fail");
}
/*
OUTPUT
Roll No:- 1
Enter Mark of Sub 1:- 78
Enter Mark of Sub 2:- 87
Enter Mark of Sub 3:- 56
Roll No:- 2
Enter Mark of Sub 1:- 45
Enter Mark of Sub 2:- 89
Enter Mark of Sub 3:- 65
Roll No:- 3
Enter Mark of Sub 1:-78
Enter Mark of Sub 2:-45
Enter Mark of Sub 3:-69
www.engiguide.com
------------------------------------------------------------------------------------------
Rank Roll no Sub 1 Sub 2 Sub 3 Total Percentage Class
------------------------------------------------------------------------------------------
2 2 45 89 65 199 66.00% First Class
1 1 78 87 56 221 73.00% Distinction
3 3 78 45 69 192 64.00% First Class
-------------------------------------------------------------------------------------------
*/

Post a Comment

0 Comments