首页 > 其他 > 详细

Exercise 2.1 Convert inches to yards, feet, and inches

时间:2014-12-13 21:40:50      阅读:416      评论:0      收藏:0      [点我收藏+]

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.

Exercise 2.1 Convert inches to yards, feet, and inches

原文:http://www.cnblogs.com/xiaomi5320/p/4161867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!