Results 1 to 2 of 2

Thread: C++ question

  1. #1

    Default C++ question

    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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: C++ question

    Sounds like a nice homework assignment. Unfortunately, we answer questions about Qt here, we don't do your homework for you.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. question about xmpp (different question)
    By davinciomar in forum Newbie
    Replies: 9
    Last Post: 6th September 2016, 13:52
  2. Question about ftp using Qt
    By lni in forum Qt Programming
    Replies: 11
    Last Post: 19th March 2014, 12:00
  3. more of a C++ question
    By jajdoo in forum Newbie
    Replies: 6
    Last Post: 17th August 2010, 20:40
  4. rcc question
    By mojo2000 in forum Newbie
    Replies: 13
    Last Post: 18th November 2009, 22:26
  5. Qt Question
    By brkapadia2003 in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2007, 12:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.