Exercise 2.1 Convert inches to yards, feet, and inches

Exercise 2-1. Write a program that prompts the user to enter a distance in inches and
then outputs that distance in yards, feet, and inches. (For those unfamiliar with imperial
units, there are 12 inches in a foot and 3 feet in a yard.)

#include <stdio.h>
int
main(void) { int inches = 0; int yards = 0; int feet = 0; const int inches_per_foot = 12; // There are 12 inches in 1 foot. const int feet_per_yard = 3; // Rhere are 3 feet in 1 yard. printf("Enter a distance in inches: "); scanf("%d", &inches); feet = inches/inches_per_foot; // Get whole feet. yards = feet/feet_per_yard; // Get whole yards in value of feet. feet %= feet_per_yard; // Get residual feet. inches %= inches_per_foot; // Get residual inches. printf("That is equivalent to %d yards %d feet and %d inches.\n", yards, feet, inches); return 0; }

 

Mark:

feet %= feet_per_yard;           // Get residual feet.
inches %= inches_per_foot;       // Get residual inches.

转载于:https://www.cnblogs.com/xiaomi5320/p/4161867.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值