Sunday, June 14, 2020
Program to calculate totalMarks, percentage and average of five subj
Write a C program to calculate total marks, percentage and average of five subjects of a student by taking marks as input from user using scanf() fucntion.
Before writing any program you just imagine about output screen first. For example: what input to be given, and output to be displayed. Let's have a look at the below example:
INPUT:
Enter secured marks of all subjects:
40
50
60
70
80
OUTPUT:
Total marks = 300.00
Percentage = 60.00
Average = 60.00
Logic to calculate total marks, percentage and average:
Step by step logic to calculate toatal marks, percenage and average.
1) Print a massage to the user like "Enter secured marks of all subjects:" using printf();
2) Input marks using scanf(); and store it in a variables: arbic, urdu, eng, hindi, and comp.
3) To get total marks sum of all subjects like: totalMarks = arbic + urdu + eng + hindi + comp
4) To calculate %, use this farmula : percentage = (totalMarks / 500) * 100
5) To calculate average use this farmula : average = totalMarks / 5
6) At last print the values of totalMarks, percentage and average. that's it!
Program to calculate totalMarks, percentage and average of all subjects:
Output:
Note: In above example: Statements scanf("%f%f%f%f%f", &arabic, &urdu, &hindi, &eng, &comp); format specifier %f is used for float data type.
And statements, printf("Total marks = %.2f\n", totalMarks); %.2f is used to print the number in decimal format upto 2 digits after dot. For Example: 300.00, 60.00 etc.
Visit to know more about Format specifier.











Help others by sharing this page.

Ahmad Irshad
Author & Editor
I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP
Sunday, June 14, 2020
C
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.