Lesson 03: Basic I/O Function

Input and output are the basic elements of the program. The computer needs to input the data, processing 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:
    • Creates two variables, num and denom, that represent the numerator (top) and denominator (bottom) of a fraction.
    • Aska 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 interaction with this program might look like below:

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

  2. ee