Practice Assignment

(squares3.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. If either of the values is less than or equal to 0, or if the range is greater than 1290, you should ask the user to re-enter the two numbers. (Why is a range greater than 1290 a problem?)

    Here's an interactive sample run with the user input in RED):

    Enter two integers greater than 0: -4 9
    Enter two integers greater than 0: 8 -5
    Enter two integers greater than 0: 22 0
    Enter two integers greater than 0: 0 123
    Enter two integers greater than 0: -5 0
    Enter two integers greater than 0: 1300 20
    Enter two integers greater than 0: 200 13
    
     Value     Value^2    Value^3
    -----------------------------
       13         169        2197
       26         676       17576
       39        1521       59319
       52        2704      140608
       65        4225      274625
       78        6084      474552
       91        8281      753571
      104       10816     1124864
      117       13689     1601613
      130       16900     2197000
      143       20449     2924207
      156       24336     3796416
      169       28561     4826809
      182       33124     6028568
      195       38025     7414875
    
    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: 12.

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

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

    Output file: output.txt You'll notice that the input numbers are not in the output, nor are any of the extra newlines.

Notes