In: Computer Science
One way to determine how healthy a person is by measuring the
body fat of the person.
The formulas to determine the body fat for female and male are as
follows:
Body fat formula for women:
Body fat formula for men:
In C program
Write a program that asks for the gender and the all the input appropriate to the gender, then calculate and display the Body Fat and Body Fat Percentage.
Example (Numbers and symbols with underscore indicate an input):
This program determines the body fat of a person.
Enter your gender (f|F|m|M): F
Enter body weight (in pounds): 120
Enter wrist measurement at fullest point (in inches): 5
Enter waist measurement at navel (in inches): 32
Enter hip measurement at fullest point (in inches): 36
Enter forearm measurement at fullest point (in inches): 23
Body fat: 25.586643
Body fat percentage: 21.322203
--------------------------------------------
This program determines the body fat of a person.
Enter your gender (f|F|m|M): m
Enter body weight (in pounds): 120
Enter waist measurement at fullest point (in inches): 5
Body fat: -83.510000
Body fat percentage: -69.591667
Following is the C program :
#include<stdio.h>
void main()
{
char ch;
int weight, waist, wrist, hip, farm ;
float A1, A2, A3, A4, A5, B, bfat, bfatp;
printf("This program determines the body fat of a person.");
printf("Enter your gender (f|F|m|M):");
scanf("%c",&ch);
if(ch=="m" || ch=="M")
{
printf("Enter body weight (in pounds): ");
scanf("%d",&weight);
A1= weight * 1.082 + 94.42;
printf("Enter waist measurement at fullest point (in inches): ");
scanf("%d",&waist);
A2= * 4.15;
B=A1-A2;
bfat=weight-B;
bfatp= bfat*100/weight;
printf("Body fat: %f",bfat);
printf("Body fat percentage: %f",bfatp);
}
else if(ch=="F" || ch=="f")
{
printf("Enter body weight (in pounds): ");
scanf("%d",&weight);
A1 = Body Weight * 0.732 + 8.987;
printf("Enter wrist measurement at fullest point (in inches):");
scanf("%d",&wrist);
A2 = wrist / 3.140;
printf("Enter waist measurement at navel (in inches): ");
scanf("%d",&waist);\
A3 = waist * 0.157;
printf("Enter hip measurement at fullest point (in inches):");
scanf("%d",&hip);
A4 = hip* 0.249;
printf("Enter forearm measurement at fullest point (in inches):");
scanf(%d",&farm);
A5 = farm* 0.434;
B = A1 + A2 - A3 - A4 + A5;
bfat = weight - B;
bfatp = bfat * 100 / weight;
printf("Body fat: %f",bfat);
printf("Body fat percentage: %f",bfatp);
}
}