Student Result Calculation Program – Create a Program that calculates the total and percentage of marks for 5 subjects using pointers for input, calculation, and output.
#include <stdio.h>
// Function prototypes
void inputMarks(int *marks);
void calculateResult(int marks[], int *total, float *percentage);
void displayResult(int total, float percentage);int main() {
// Declare variables
int subjectMarks[5];
int totalMarks;
float percentage;// Input marks for each subject
inputMarks(subjectMarks);// Calculate total and percentage
calculateResult(subjectMarks, &totalMarks, &percentage);// Display result
displayResult(totalMarks, percentage);return 0; // Exit successfully
}// Function to input marks for 5 subjects using call by reference
void inputMarks(int *marks) {
printf(“Enter marks for 5 subjects:n”);for (int i = 0; i < 5; i++) {
printf(“Subject %d: “, i + 1);
scanf(“%d”, &marks[i]);// Validate marks (assuming marks should be between 0 and 100)
if (marks[i] < 0 || marks[i] > 100) {
printf(“Invalid marks. Marks should be between 0 and 100.n”);
// You may choose to handle the error here or return an error code
return;
}
}
}// Function to calculate total and percentage using call by reference
void calculateResult(int marks[], int *total, float *percentage) {
*total = 0;for (int i = 0; i < 5; i++) {
*total += marks[i];
}*percentage = (float)(*total) / 5;
}// Function to display result using call by value
void displayResult(int total, float percentage) {
printf(“nTotal Marks: %dn”, total);
printf(“Percentage: %.2f%%n”, percentage);// Determine pass or fail (assuming passing percentage is 40)
if (percentage >= 40) {
printf(“Result: Passn”);
} else {
printf(“Result: Failn”);
}
}