Course: Programming Fundamentals

In Lab Assignment 7

Question 1:

Write a program that prints the following output on the screen

1 2 3 4 5

3 4 5 6

5 6 7

7 8

9

Question 2:

Write a program that prints the following output on the screen

1 1 1 1 1

2 3 4 5

3 3 3

4 5

5

Question 3:

Write a program that displays a table resembling spreadsheet. The column headings should show the values A,B,C,D and E and the row headings should show 1,2,3,4,5. The row values should be multiples of the value of the row number. Use a for loop to output the column headings. Use nested for loops to output the row number and the values within the rows and columns. The output should look like the following:

Question 4:

Write an entire C++ program that reads a positive integer entered by an interactive user and then prints out all the positive divisors of that integer in a column and in decreasing order. The program should allow the user to repeat this process as many times as the user likes. Initially, the program should inform the user about how the program will behave. Then the program should prompt the user for each integer that the user wishes to enter. Make sure the program does not accept any negative or zero input. When the user accidentally enters a zero or negative integer to have its divisors calculated, the program should inform the user that the input is unacceptable and should allow the user to try again (and again!).

Sample Run:

Please enter a positive integer: 36

36

18

12

9

6

4

3

2

1

Would you like to see the divisors of another integer (Y/N)? y

Please enter a positive integer: -44

-44 is not a positive integer.

Please enter a positive integer: 0

0 is not a positive integer.

Please enter a positive integer: 109

109

1

Would you like to see the divisors of another integer (Y/N)? m

Please respond with Y (or y) for yes and N (or n) for no.

Would you like to see the divisors of another integer (Y/N)? n

Question 5:

Write a program, which generates and prints a triangle of numbers. The triangle should be generated using two integer inputs, one is for the size of triangle and other is for the start value of triangle. Size gives the number of columns. Start value specifies the first value of the first column. Column n contains n values. The successive values are obtained by adding 1 to the previous value. When 9 is reached, the next value becomes 1.

Note: Your program should print the numbers in the form of triangle exactly as shown below. The space between two numbers is optional.

Following are the examples of the expected output for two different inputs.

Size 6, start 1

1 2 3 4 5 6

7 8 9 1 2

3 4 5 6

7 8 9

1 2

3

Size 5, start 3

3 4 5 6 7

8 9 1 2

3 4 5

6 7

8

======