Q-8.Write a C program to input marks of five subjects of a student and calculate total, average and percentage of all subjects. How to calculate total, average and percentage in C programming. Logic to find total, average and percentage in C program.

1 minute read
0
  1. /**
  2. * C program to calculate total, average and percentage of five subjects */


  3. #include <stdio.h>
  4. int main()
  5. { float eng, phy, chem, math, comp;


  6. float total, average, percentage;
  7. /* Input marks of all five subjects */ printf("Enter marks of five subjects: \n");


  8. scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);
  9. /* Calculate total, average and percentage */ total = eng + phy + chem + math + comp;


  10. average = total / 5.0; percentage = (total / 500.0) * 100;


  11. /* Print all results */


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


  13. printf("Percentage = %.2f", percentage);
    1. return 0;
  • }




Post a Comment

0Comments
Post a Comment (0)