PDA

View Full Version : C++ question



iijiihin
5th October 2016, 16:29
Write a C++ program that will ask the user for two positive integers a and b. You may assume that both a and b are in the set { 0, 1, 2, ..., 999} and that a < b.
The user will then be prompted to enter divisors (zero or more). You may assume that all divisors are in the set { 1, 2, 3, ..., 999}. The user will be prompted to add a divisor until the user indicates that they are finished. This will be done by entering -1. You may assume that the user enters from zero to at most four divisors followed by -1 to terminate the list.

Finally, your program should output a matrix with the following elements.

An M in the upper left corner.
The first row, after the M, will contain the divisors in input order.
The first column after the M will contain all integers from a to b-1 in increasing order.
A 1 at row i+1 and column j+1 if the i-th integer is divisible by the j-th divisor, otherwise a 0.
Matrix elements should be separated by a space.

Sample Run

a: 1
b: 16
Add divisor: 2
Add divisor: 3
Add divisor: -1
M 2 3
1 0 0
2 1 0
3 0 1
4 1 0
5 0 0
6 1 1
7 0 0
8 1 0
9 0 1
10 1 0
11 0 0
12 1 1
13 0 0
14 1 0
15 0 1

a: 2
b: 7
Add divisor: 5
Add divisor: -1
M 5
2 0
3 0
4 0
5 1
6 0

a: 2
b: 7
Add divisor: 5
Add divisor: 4
Add divisor: -1
M 5 4
2 0 0
3 0 0
4 0 1
5 1 0
6 0 0

a: 55
b: 60
Add divisor: -1
M
55
56
57
58
59

d_stranz
5th October 2016, 17:17
Sounds like a nice homework assignment. Unfortunately, we answer questions about Qt here, we don't do your homework for you.