-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQ25.c
50 lines (49 loc) · 1.32 KB
/
Q25.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Program: 25
Write a 'C' Program to create a structure of student having fields roll_no,
stud_name, mark1, mark2, mark3. Calculate total marks and average marks.
Arrange the records in descending order of marks.
*/
#include <stdio.h>
#include <string.h>
struct student
{
int rollNo;
char studName[30];
int mark[3];
} st;
int main()
{
int i, t, j, sum = 0;
printf("Enter the student roll no : ");
scanf("%d", &st.rollNo);
fflush(stdin);
printf("Enter the student name : ");
gets(st.studName);
for (i = 0; i < 3; i++)
{
printf("Enter mark%d : ", i + 1);
scanf("%d", &st.mark[i]);
sum = sum + st.mark[i];
}
for (j = 0; j < 3; j++)
{
for (i = 0; i < 3 - j; i++)
{
if (st.mark[i] < st.mark[i + 1])
{
t = st.mark[i];
st.mark[i] = st.mark[i + 1];
st.mark[i + 1] = t;
}
}
}
printf("\nName : %s\n", st.studName);
printf("Roll no : %d\n", st.rollNo);
printf("\naverage marks : %d\n", sum / 3);
printf("\n\t_____descending order of marks_____\n");
for (i = 0; i < 3; i++)
{
printf("%d\n", st.mark[i]);
}
return 0;
}