Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can u help me,please

  1. Jun 29, 2006 #1
    Hi,,
    I am hoping that you will help me. I have trouble how can do this homework:
    Write a program that allows the user to input a number of integers such as N, and then stores them in an integer matrix where:

    1- The dimension of matrix = NXN.
    2-Entries of matrix can take any number from 0-2.
    3- Arrangement of entries of first row is the same arrangement of entries of first column.
    4-The diagonal of matrix =o.
    5- Total of every row =4,Also Total of every column.

    Then, the program displays the result.

    Your help would greatly be appreciated

    Respectfully,,
    Miss_Lolitta
     

    Attached Files:

  2. jcsd
  3. Jun 30, 2006 #2
    Is there a particular language that the program is to be written in?
     
  4. Jun 30, 2006 #3
    hey perhaps we can sit your exams for you too?

    At least try and do it, and post what progress you have gotten through!
     
  5. Jun 30, 2006 #4
    Isn't this in the wrong section? Shouldn't it be in the homework section?
     
  6. Jun 30, 2006 #5
    I would like to write this program in C++.I learn the programming language at an institute,and I am not expert in this branch but I try to become better with your first help.

    I would be so ever grateful if you could help me on how to go about writing this program.

    thanks,,
     
  7. Jun 30, 2006 #6

    DaveC426913

    User Avatar
    Gold Member

    OK, forget about the programming language, forget about the computer. Pick up a pencil.

    Design you logic first. Start at a high level, then break it down.
    1] Gets integer from user: N.
    2] Creates a matrix: NxN.
    3] Fills in the diagonal values with zeros.
    4] ?? - You must decide on your algorthim for checking against your rules.

    Clearly step 4 is the bulk of the program. How do you propose to check?
    Brute force?
    000 000 000 = No.
    000 000 001 = No
    000 000 002 = No
    000 000 010 = No
    etc.
    Is there a better way to do this? Knowing the rules you have to stay within, and the possible values (0-2), are there any steps you can eliminate? (Note that of the above tests, only 2 of them are valid, considering the "diagonal rule". You don't even need to test them.)

    Hint: you're going to be needing a lot of loops and a lot of 'if's.

    There is no point in going anywhere near a programming language or a computer until you've worked out your logic.
     
    Last edited: Jun 30, 2006
  8. Jul 1, 2006 #7
    Really, forget about the programming language, forget about the computer. Look at this method to solve this problem in maths:

    1] Gets integer from user: N. such as N=3

    2] Creates a matrix: 3x3

    X Y Z
    X Y Z
    X Y Z

    3] Fills in the diagonal values with zeros.

    0 Y Z
    X 0 Z
    X Y 0

    >>> then we have the following system:

    0 Y Z = 4
    X 0 Z = 4
    X Y 0 = 4

    >>> by solving this system we have a unique solution:X=2,Y=2,Z=2

    >>> So, we have matrix

    0 2 2
    2 0 2
    2 2 0


    Hint: we have a symmetry between diagonals of matrix

    I know that there is relation between maths and CS to solve mathematical problems..because of this I would like to study the programming languages.

    Any help you give I'd be very glad . Thank you for your assistance.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Can u help me,please
  1. Can u help me ? (Replies: 2)

Loading...