Exercise 2.1 Convert inches to yards, feet, and inches

Source: Internet
Author: User

Exercise 2-1. Write A program this prompts the user to enter a distance in inches and
Then outputs this distance in yards, feet, and inches. (For those unfamiliar with imperial
Units, there is inches in a foot and 3 feet in a yard.)

#include <stdio.h>
intMainvoid){ intinches =0; intYards =0; intFeet =0; Const intInches_per_foot = A;//there is inches in 1 foot. Const intFeet_per_yard =3;//Rhere is 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's 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.