zoukankan      html  css  js  c++  java
  • 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. ", yards, feet, inches); return 0; }

    Mark:

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

  • 相关阅读:
    路由协议
    TDD一示范例
    leetcode-36 + this may be useful when development is performed under newer sdk version
    leetcode-35
    TCP扫盲1
    UDP扫盲
    leetcode-34
    leetcode-33
    leetcode-32
    mysql非常全的和完整的总结
  • 原文地址:https://www.cnblogs.com/xiaomi5320/p/4161867.html
Copyright © 2011-2022 走看看