Male and Female Percentages Write a program that asks the user for the number of
ID: 669829 • Letter: M
Question
Male and Female Percentages Write a program that asks the user for the number of males and the number of females registered in a class. The program should display the percentage of males and females in the class. Hint: Suppose there are 8 males and 12 females in a class. There are 20 students in the class. Hint: Suppose there are 8 males and 12 females in a class. There are 20 students in the class. The percentage of males can be calculated as 8 20 = 0.4, or 40%. The percentage of females can be calculated as 12 20 = 0.6, or 60%.
Explanation / Answer
#include <stdio.h>
int main(void) {
int male,female,total;
printf("Enter number of males in the class: ");
scanf("%d",&male);
printf("Enter number of females in the class: ");
scanf("%d",&female);
total=male+female;
double maleP,femaleP;
maleP=male/total;
maleP=maleP*100;
femaleP=100-maleP;
printf("Male percentage in the class: %lf",maleP);
printf("female percentage in the class: %lf",femaleP);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.