Home C Programming Language / 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,539 Views
💻 Practical Program
📘 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;
}
                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.