This C program converts Centimeters to Feet and Inches:
//*************************************************
#include <stdio.h>
#define CMPERFT 30.48
float cm,ft,in;
int main (void) {
printf("Enter a height in centimeters (<=0 to quite): ");
scanf("%f", &cm );
while (cm > 0) {
ft = cm/CMPERFT;
in = (ft - (int)ft) * 12; //You can't find a remainder of a float with modulus.So use Cast
printf("\n%0.2f cm = %d feet, %0.3f inches\n", cm, (int)ft ,in);
printf("Enter a height in centimeters (<=0 to quite): ");
scanf("%f", &cm );
}
return 0;
}
//************************************************
No comments:
Post a Comment