1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matrix operations in C language

  1. Jun 30, 2007 #1
    i have a matrix 4x4 like this

    1 5 7 3
    2 6 8 0
    1 4 3 2
    0 4 0 5

    my teacher asks me to print out 1 2 3 4
    each of the digits is from the 1st 2nd 3rd 4th rows
    it looks very simple, but because i just learnt c for two months, i don't know how to code a program, true.

    could you help me ?:shy:
    thank you
  2. jcsd
  3. Jun 30, 2007 #2
    Hello phillosopher
    The answer is quite simple.
    I am not jotting down the actual code (it is against PF rules), but I will give you a hint.
    Did you notice that the number that you have to print in each row is equal to the row-number. So just write a comparison-performing code, which compares each digit of a row with the row number. If the digit matches with the row-number, print the digit.
    You will need a nested loop (a loop inside a loop) for this. Both the external and internal loops will need four iterations.

    Mr V
  4. Jun 30, 2007 #3
    :biggrin:thank you,
    I forget that life-saving spot.
    No, I will use only one loop to output the number of rows. That'll be nicer, isn't it ?:tongue2:
  5. Jun 30, 2007 #4
    Yeah, you can easily do that. But if you want the program to look like a "searching" program (that's the topic of your thread), then the approach I suggested will be better.
    Last edited: Jun 30, 2007
  6. Jul 1, 2007 #5
    Yes, that approach is better for the searching program because I suppose I can make the program guess what number comes next especially when the numbers don't denote the row's numbers, thank you, :biggrin:
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matrix operations in C language
  1. Assembly language or C (Replies: 5)