Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Sunday, June 14, 2020

Program to calculate totalMarks, percentage and average of five subj


C Program to calculate total marks, percentage and average of five subjects:
By Ahmad Irshad | Programming Exercises and Solutions > print the result of a student

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.

Required knowledge for this exercise is


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

  1. /* C program to calculate totalMarks, percentage and average of all subjects */ #include <stdio.h> int main() { float arabic, urdu, hindi, eng, comp; float totalMarks, average, percentage; /* Input marks of all subjects */ printf("Enter marks of five subjects: \n"); scanf("%f%f%f%f%f", &arabic, &urdu, &hindi, &eng, &comp); /* Calculate totalMarks, average and percentage */ totalMarks = arabic + urdu + hindi + eng + comp; average = totalMarks / 5.0; percentage = (totalMarks / 500.0) * 100; /* Print all results */ printf("Total marks = %.2f\n", totalMarks); printf("Average = %.2f\n", average); printf("Percentage = %.2f", percentage); return 0; }

Output:

  1. Enter marks of five subjects:
  2. 40
  3. 50
  4. 60
  5. 70
  6. 80

  7. Total Marks = 300.00
  1. Average = 60.00
  2. Percentage = 60.00

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.




Next Topic to be updated soon..>>




Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

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

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us