0% found this document useful (0 votes)
21 views2 pages

Excersize 3

c program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Excersize 3

c program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C program to calculate total

average and percentage of five


subjects
Example
Input
Enter marks of five subjects: 95 76 85 90 89

Output

Total = 435
Average = 87
Percentage = 87.00

Logic to find total, average and percentage


Step by step descriptive logic to find total, average and percentage.

1. Input marks of five subjects. Store it in some variables say eng, phy, chem, math and comp.


2. Calculate sum of all subjects and store in total = eng + phy + chem + math +
comp.
3. Divide sum of all subjects by total number of subject to find average i.e. average =
total / 5.
4. Calculate percentage using percentage = (total / 500) * 100.
5. Finally, print resultant values total, average and percentage.

/**
* C program to calculate total, average and percentage of five subjects
*/

#include <stdio.h>

int main()
{
float eng, phy, chem, math, comp;
float total, average, percentage;

/* Input marks of all five subjects */


printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);

/* Calculate total, average and percentage */


total = eng + phy + chem + math + comp;
average = total / 5.0;
percentage = (total / 500.0) * 100;

/* Print all results */


printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);

return 0;
}

OUTPUT

Output
Enter marks of five subjects:
95
76
85
90
89
Total marks = 435.00
Average marks = 87.00
Percentage = 87.00

You might also like