Write a C program to compute the maximum marks and average marks of a class using sentinel controlled repetition (-1 as the sentinel value)?- If user enters negative marks then display INVALID INPUT and and read the marks again.- If number of students is 0, then display "NO DATA"- If number of students > 0, then display maximum marks and the average marks separated by space.-You can assume that marks are integers and average also you discard decimal value.
Question
Write a C program to compute the maximum marks and average marks of a class using sentinel controlled repetition (-1 as the sentinel value)?- If user enters negative marks then display INVALID INPUT and and read the marks again.- If number of students is 0, then display "NO DATA"- If number of students > 0, then display maximum marks and the average marks separated by space.-You can assume that marks are integers and average also you discard decimal value.
Solution
Here is a simple C program that fulfills your requirements:
#include <stdio.h>
int main() {
int marks, count = 0, sum = 0, max = 0;
while(1) {
printf("Enter marks: ");
scanf("%d", &marks);
if(marks == -1) {
break;
} else if(marks < -1) {
printf("INVALID INPUT\n");
continue;
}
if(marks > max) {
max = marks;
}
sum += marks;
count++;
}
if(count == 0) {
printf("NO DATA\n");
} else {
printf("Maximum marks: %d\n", max);
printf("Average marks: %d\n", sum/count);
}
return 0;
}
This program works as follows:
- It initializes variables for the count of marks, the sum of marks, and the maximum mark.
- It enters an infinite loop, asking the user to enter marks.
- If the user enters -1, it breaks the loop.
- If the user enters a number less than -1, it prints "INVALID INPUT" and continues to the next iteration of the loop.
- If the user enters a valid mark, it updates the maximum mark if necessary, adds the mark to the sum, and increments the count.
- After the loop, if no marks were entered, it prints "NO DATA". Otherwise, it prints the maximum mark and the average mark (truncated to an integer).
Similar Questions
You are developing a Student Record Management System in C. The system needs to store and manage information for multiple students, including their names, roll numbers, and marks obtained in different subjects. Implement array in structures to read, write, and compute average marks and the students scoring above and below the average marks for a class of N students. INPUT/OUTPUT EXAMPLE: Enter the number of students: 3 Enter details for 3 students: Student 1: Name: A Roll Number: 1 Marks in 5 subjects: Subject 1: 12 Subject 2: 13 Subject 3: 14 Subject 4: 15 Subject 5: 16 Student 2: Name: BB Roll Number: 2 Marks in 5 subjects: Subject 1: 11 Subject 2: 13 Subject 3: 12 Subject 4: 15 Subject 5: 14 Student 3: Name: CC Roll Number: 10 Marks in 5 subjects: Subject 1: 13 Subject 2: 14 Subject 3: 16 Subject 4: 17 Subject 5: 11 Class average marks: 13.73 Students scoring above average: A (Roll Number: 1) CC (Roll Number: 10) Students scoring below average: BB (Roll Number: 2)
# Write a function in python which accept a list of marks of students and return the# minimum mark, maximum mark and the average marks. Use the same function to test
Write a C program using structure student which allows users to input details for three students including their names, roll numbers, and marks in 5 subjects. Use a function calculateTotalMarks(struct Student) which calculates the total marks and percentage for each student and displays the information. Each subject test is for 10 marks. Total marks = 50. Percentage = (marks obtained/total marks)*100.
In this exercise you will create a program that computes the average of a collection of values entered by the user. The user will enter 0 as a sentinel value to indicate that no further values will be provided. Your program should display an appropriate error message if the first value entered by the user is 0.Hint: Because the 0 marks the end of the input it should not be included in the average.
Write a program to write data into binary file marks.dat anddisplay the records of students who scored more than 95marks.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.