- Write a program asking the user to enter a number between 1 and 100. Validate the input. Use a while loop and a counter to print the first 20 multiples of that number.
Sample run of program:
Enter a number between 1 and 100:
> 102
Invalid input! Enter a number between 1 and 100:
> 3
The first 20 multiples of 3 are 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60
- Write a program that prompts the user for a number greater than 100, the prints all positive integers whose square is less than the number provided by the user, in a table with the left-hand column being the integer and the right-hand column being the square of the integer.
Sample run of program:
Enter a number greater than 100:
> 2
Invalid input! Enter a number greater than 100:
> 150
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
11 121
12 144
- Write a program that computes the average test score over an unspecified number of tests as follows: (1) Ask the user to enter numeric grades; (2) as long as there are more grades, add them to the total; (3) use a counter variable to track the number of grades entered by the user; (4) stop when the user enters a negative score; (5) output the average grade for the class.
Sample run of program:
Enter a numeric grade:
> 78
Enter a numeric grade:
> 89
Enter a numeric grade:
> 77
Enter a numeric grade:
> 90
Enter a numeric grade:
> 97
Enter a numeric grade:
> 92
Enter a numeric grade:
> -1
The average grade is 87.1667
- Write a program that prompts the user for a number between 10 and 20. If the user enters a number outside that range, end the program. Use a for loop to print a row of alternating charactesr (^ and *) ef length equal to the user's number.
Sample run of the program:
Enter a number between 10 and 20: 17
^*^*^*^*^*^*^*^*^
- Write a program that prompts the user for a number between 2 and 5. Using a loop and multiplication only, print the first 10 powers of that number.
Sample run of the program:
Enter a number between 2 and 5: 2
2
4
8
16
32
64
128
256
512
1024