Write an interactive program called “WEIGHT CONVERTER”
that accepts the weight in milligrams / decigrams / centigrams /
kilograms /ounces / pounds / tons and displays its equivalent in
grams.
that accepts the weight in milligrams / decigrams / centigrams /
kilograms /ounces / pounds / tons and displays its equivalent in
grams.
#include <stdio.h>
void print_converted(int pounds)
/* Convert U.S. Weight to Imperial and International
Units. Print the results */
{ int stones = pounds / 14;
int uklbs = pounds % 14;
float kilos_per_pound = 0.45359;
float kilos = pounds * kilos_per_pound;
printf(" %3d %2d %2d %6.2f",
pounds, stones, uklbs, kilos);
}
main(int argc,char *argv[])
{ int pounds;
if(argc != 2)
{ printf("Usage: convert weight_in_pounds");
exit(1);
}
sscanf(argv[1], "%d", £s); /* Convert String to int */
printf(" US lbs UK st. lbs INT Kg");
print_converted(pounds);
}
No comments:
Post a Comment