#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    Need help in writing a code (assignment)


    I need to write a code (in C99). The programe receives an input number (integer) 'n' and then a matrix sized n*n (matrix[n][n]), all numbers are integers. We're supposed to define the matrix's size with malloc.
    Now the program needs to sort the lines of the matrix (the number in each line), in a single function (!) this way:
    even line index (0,2,4,6...): from small to big.
    odds line index (1,3,5...): from big to small.
    and then print it.
    *note: first line is indexed 0, second line is 1, etc.

    I was thinking to sort it with bubblesort function with the following if:
    if(i%2==1)
    do odds sorting.
    else
    do even sorting.
    when i is the index of the row.

    my problem is defining the malloc and how do I send the matrix to sorting.
    please help :( even a general direction, or a tip would help.

    If needed I will attach my current (not so good (completly awful)) code and functions as well as an example of what the prog. supposed to do.

    *sorry for grammer.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo