Total, average and % of 5 subjects in C

Here’s a C program that accepts marks in 5 subjects and calculates the average marks:

					#include <stdio.h>

int main() {
  char character;

  printf("Enter a character: ");
  scanf("%c", & character);

  printf("The ASCII value of '%c' is %d.\n", character, character);

  return 0;
C Program that Accepts marks in 5 Subjects and Outputs Average Marks
  • In this program, we declare an integer array marks of size 5 to store the marks in the 5 subjects. We also declare variables i for the loop counter, total to calculate the sum of marks, and average to store the calculated average marks.

  • The program prompts the user to enter marks in 5 subjects using a for loop. Inside the loop, the user is prompted for the marks of each subject, which are then stored in the marks array. The total variable is incremented by each entered mark, thus calculating the sum of marks.

  • After the loop, the average marks are calculated by dividing the total by 5, which is the number of subjects.

  • Finally, the program displays the average marks using printf with the %f format specifier for the floating-point value. The .2 in %.2f specifies that the average should be displayed with two decimal places.