Practice Assignment

(squares2.c)

Information

  1. Write a program that asks the user to input 2 integers that are greater than 0. Let's call these two values range and stride, respectively. Let's assume range is 50 and stride is 3. Now, print the table below. (The user input is in RED)
    Enter two integers greater than 0: 50 3
    
     Value     Value^2    Value^3
    -----------------------------
        3           9          27
        6          36         216
        9          81         729
       12         144        1728
       15         225        3375
       18         324        5832
       21         441        9261
       24         576       13824
       27         729       19683
       30         900       27000
       33        1089       35937
       36        1296       46656
       39        1521       59319
       42        1764       74088
       45        2025       91125
       48        2304      110592
    
    You'll notice that you're printing the stride in the left column, the stride squared in the middle column, and the stride cubed in the right column. Then, you increment the stride by itself and print out the new values on the next line. Continue until the value in the left column is greater than the range that was input. Your output must match exactly.

    Approximate number of lines of code: 10.

    The name of the file should be squares2.c and the command to compile it will look like this:

    gcc -Werror -Wall -Wextra -ansi -pedantic squares2.c -o squares2 -O2 -Wno-unused-result
    
    When you've got it working, use these files to redirect the input into output files. For example:
    squares2 < input50-3.txt > myoutput50-3.txt
    
    Input files:

    Output files: (You'll notice that the input numbers are not in the output, nor is the extra blank line.)

Notes