-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverage Marks,Highest Mark,Lowest Mark,Count ds 1 (i-v)
More file actions
96 lines (90 loc) · 2.64 KB
/
Copy pathAverage Marks,Highest Mark,Lowest Mark,Count ds 1 (i-v)
File metadata and controls
96 lines (90 loc) · 2.64 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*1. A teacher is inputting the marks of his students for a Mathematics test. The marks range
from 0 to 100.
i) Calculate the Average Marks of the Students:
Write a program to input the marks of n students and calculate the average marks.
ii) Find the Highest Mark:
Write a program to input the marks of n students and find the highest mark obtained in
the test.
iii)Find the Lowest Mark:
Write a program to input the marks of n students and find the lowest mark obtained in
the test.
iv) Count Students with Marks Above Average:
Write a program to input the marks of n students and calculate the average marks.
Then, count how many students scored marks above the average.
v) Calculate Grade Distribution:
Extend the previous program to categorize students' marks into different grade
bands: A (90-100), B (80-89), C (70-79), D (60-69), and F (below 60).
Output the count of students in each grade band. */
#include<stdio.h>
int main()
{
int n; //students number from user
printf("Enter the number of students:");
scanf("%d",&n);
int arr[n]; //the marks from user
printf("Enter the results for students:\n");
for (int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("\n");
int sum=0; //the average code
for (int i=0;i<n;i++)
{
sum=sum+arr[i];
}
double ave=(double)sum/n;
printf("The average:%.4f\n",ave);
int max=arr[0]; //max, min code
int min=arr[0];
for (int i=0;i<n;i++)
{
if(arr[i]>max)
{
max=arr[i];
}
if(arr[i]<min)
{
min=arr[i];
}
}
printf("The highest mark is: %d\n",max);
printf("The lowest mark is: %d\n",min);
printf("\n");
int count=0;
for (int i=0;i<n;i++){
if(arr[i]>ave)
{
count++;
}
}
//The number of students who got above average mark code
printf("The number of students who got above average mark is:%d\n",count);
printf("\n");
int count1=0;
int count2=0;
int count3=0;
int count4=0;
int count5=0;
for (int i=0;i<n;i++){
// Grade Distribution code
if(arr[i]>=90 && arr[i]<101){
count1++;
}else if(arr[i]>=80 && arr[i]<90){
count2++;
}else if(arr[i]>=70 && arr[i]<80){
count3++;
}else if(arr[i]>=60 && arr[i]<70){
count4++;
}else {count5++;}
}
printf("The numbers of students who got A,B,C,D and F are: %d, %d, %d, %d,
%d.",count1,count2,count3,count4,count5);
printf("\n");
printf("Grade A (90-100): %d students\n", count1);
printf("Grade B (80-89): %d students\n", count2);
printf("Grade C (70-79): %d students\n", count3);
printf("Grade D (60-69): %d students\n", count4);
printf("Grade F (below 60): %d students\n",count5);
return 0;
}