這是我的:)
/*
* CHANGE THE UNIT OF WEIGHT FROM GRAM TO POUND AND OUNCE.
*/
#include <stdio.h>
#define OUNCE_PER_GRAM 0.0352
#define OUNCE_PER_LB 16
int
main(void)
{
double gram,
ounce;
int lb;
printf("Enter the weight in grams> ");
scanf("%lf", &gram);
if(gram >= 0)
{
ounce = OUNCE_PER_GRAM * gram;
lb = ounce / OUNCE_PER_LB ;
ounce = ounce - lb * OUNCE_PER_LB;
printf("%f grams equals %d pounds %f ounces.\n", gram, lb, ounce);
}
else
{
printf("You may enter a wrong number.\n");
printf("Please restart this program. ^_^ \n");
}
return (0);
}
if敘述的用法在第4章
有興趣的同學可以自己去翻翻看^_^
--
A(Animation)
C(Comic)
G(Game)
乃精神之三大營養素
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: 64.c240.ethome.