首页 > 代码库 > Exercise 2.1 Convert inches to yards, feet, and inches
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.
Exercise 2.1 Convert inches to yards, feet, and inches
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。