Lesson 03: Basic I/O Function

Input and output are the basic elements of the program. The computer needs to input the data, process the data, then output the results. The basic input and output are keyboard and screen: read data from the keyboard, and print the results on the screen. This lesson describes the basic input and output functions in C and C++. Lesson 16 will introduce input and output functions for file access.

 

Questions

  1. Write a program that does the following:
    • Create two variables, num and denom, that represent a fraction's numerator (top) and denominator (bottom).
    • Ask the user to supply values for the numerator and denominator.
    • Puts the values supplied into the variables
    • Displays the fraction in the format 2/3, with a slash between the two numbers.

    Some sample interactions with this program might look like below:

    Enter the numerator: 4
    Enter the denominator: 7
    Fraction = 4/7

  2. Let me think about it ...