Question: Q2: (Integer Sequences with While Loops) (20 points): Loops are very useful for counting and generating sequences of integers. If you can use a variable
Q2: (Integer Sequences with While Loops) (20 points): Loops are very useful for counting and generating sequences of integers. If you can use a variable with a loop to count from 0 to n, then you can often transform that variable n using a formula or function such that f(n) results in a new integer sequence. Write a program that prompts the user to enter a number between 2 and 20, and then uses a series of while loops to generate some interesting integer sequences. The loop counters should all start at zero, but the transformed number may start at a number other than zero. The exact prompts and outputs needed can be found in the sample output given below. Use 2 spaces between each integer printed. Your program output should look as follows: Sample Input and Output: Enter a number between 2 and 20: 8 The first 8 whole numbers: 0 1 2 3 4 5 6 7 The first 8 even whole numbers: 0 2 4 6 8 10 12 14 The first 8 odd whole numbers: 1 3 5 79 11 13 15 The first 8 whole numbers counting by 7: 0 7 14 21 28 35 42 49 The first 8 perfect squares: 0 1 4 9 16 25 36 49
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
