Home / Programs / If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
Programming Example

If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

👁 1,534 Views
💻 Practical Program
📘 Step by Step Learning

If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

Information & Algorithm

Given Input:

Enter marks obtained in subject 1: 50
Enter marks obtained in subject 2: 60
Enter marks obtained in subject 3: 70
Enter marks obtained in subject 4: 80
Enter marks obtained in subject 5: 90

Expected Output:

Total marks obtained: 350.00
Percentage marks obtained: 70.00

Program Code

#include <stdio.h>

int main()
{
    int marks1, marks2, marks3, marks4, marks5;
    float total, percentage;

    printf("Enter marks obtained in subject 1: ");
    scanf("%d", &marks1);

    printf("Enter marks obtained in subject 2: ");
    scanf("%d", &marks2);

    printf("Enter marks obtained in subject 3: ");
    scanf("%d", &marks3);

    printf("Enter marks obtained in subject 4: ");
    scanf("%d", &marks4);

    printf("Enter marks obtained in subject 5: ");
    scanf("%d", &marks5);

    total = marks1 + marks2 + marks3 + marks4 + marks5;
    percentage = (total/500) * 100;

    printf("Total marks obtained: %.2f\n", total);
    printf("Percentage marks obtained: %.2f\n", percentage);

    return 0;
}

Output

Enter marks obtained in subject 1: 50
Enter marks obtained in subject 2: 60
Enter marks obtained in subject 3: 70
Enter marks obtained in subject 4: 80
Enter marks obtained in subject 5: 90
Total marks obtained: 350.00
Percentage marks obtained: 70.00

Explanation

  1. Start the program by including the standard input/output library
  2. Create variables for marks1, marks2, marks3, marks4, marks5, total, and percentage as integers
  3. Print a message requesting the user to input the marks obtained in subject 1 and store the value in marks1
  4. Print a message requesting the user to input the marks obtained in subject 2 and store the value in marks2
  5. Print a message requesting the user to input the marks obtained in subject 3 and store the value in marks3
  6. Print a message requesting the user to input the marks obtained in subject 4 and store the value in marks4
  7. Print a message requesting the user to input the marks obtained in subject 5 and store the value in marks5
  8. Calculate the total marks obtained by adding all the marks together and store the value in total
  9. Calculate the percentage marks obtained by dividing the total marks by 500 and multiplying by 100 and store the value in percentage
  10. Print the total marks obtained and the percentage marks obtained
  11. End the program

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.