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.
C Programming Language Operators and Enums in C Language (Article) Operators and Enums in C Language (Program)
1258
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:
#include
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:
- Start the program by including the standard input/output library
- Create variables for marks1, marks2, marks3, marks4, marks5, total, and percentage as integers
- Print a message requesting the user to input the marks obtained in subject 1 and store the value in marks1
- Print a message requesting the user to input the marks obtained in subject 2 and store the value in marks2
- Print a message requesting the user to input the marks obtained in subject 3 and store the value in marks3
- Print a message requesting the user to input the marks obtained in subject 4 and store the value in marks4
- Print a message requesting the user to input the marks obtained in subject 5 and store the value in marks5
- Calculate the total marks obtained by adding all the marks together and store the value in total
- Calculate the percentage marks obtained by dividing the total marks by 500 and multiplying by 100 and store the value in percentage
- Print the total marks obtained and the percentage marks obtained
- End the program
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.
Total marks obtained: 350.00 Percentage marks obtained: 70.00
Program:
#include 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:
- Start the program by including the standard input/output library
- Create variables for marks1, marks2, marks3, marks4, marks5, total, and percentage as integers
- Print a message requesting the user to input the marks obtained in subject 1 and store the value in marks1
- Print a message requesting the user to input the marks obtained in subject 2 and store the value in marks2
- Print a message requesting the user to input the marks obtained in subject 3 and store the value in marks3
- Print a message requesting the user to input the marks obtained in subject 4 and store the value in marks4
- Print a message requesting the user to input the marks obtained in subject 5 and store the value in marks5
- Calculate the total marks obtained by adding all the marks together and store the value in total
- Calculate the percentage marks obtained by dividing the total marks by 500 and multiplying by 100 and store the value in percentage
- Print the total marks obtained and the percentage marks obtained
- End the program
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.