2D array sort

Help, im using TC3.0 and i want to find the lowest value in the array below, on each row.i.e
so the first value will be 2 and next one will be 3.  i tried to work out the
answer by comparing the array to the first element but im getting 2 as the answer for each row!
i can figure out why this is happening


#include <stdio.h>
#include <conio.h>
int main()
{
      int row,col;
      int temp=0;
      int shortestJob;
      int machines [4] [5] ={
                                          {2,8,3,9,2},
                                          {3,9,8,7,6},
                                          {7,4,6,2,3},
                                          {4,6,3,5,6}
                                          
                                          };

      shortestJob=machines[0][0];
      clrscr();
      printf("%10s","Machine");
      for(col=0;col<5;col++)
            printf("%5d",col);
      printf("\n%-10s\n","Job");


      for(row=0;row<4;row++)
      {
            printf("%2d%8s",row,"");

            for(col=0;col<5;col++)
            {
                  printf("%5d",machines[row][col]);
                  if (machines [row][col] < shortestJob)
                  {
                        shortestJob=machines[row][col];
                  }


            }
            printf("\t%d",shortestJob);
            printf("\n");
      }
      printf("shortest job is %d",shortestJob);
return 0;
}

LVL 2
gerrymcdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Is this homework? Why don't you debug it? It is very easy to figure out.

Hint: The program currently finds the lowest value in the 2D array. You need to assign ??? to shortestJob when each row is started.
0
GodSlayerCommented:
For each row set shortestJob equal to the first element in the row.  Like chensu already effectively told you.
0
niemeyerCommented:

You've just forgotten to reset shortest job's value
between diferent rows.


#include <stdio.h>
#include <conio.h>

int main()
{
  int row,col;
  int temp=0;
  int shortestJob;
  int machines [4] [5] ={
    {2,8,3,9,2},
    {3,9,8,7,6},
    {7,4,6,2,3},
    {4,6,3,5,6}

  };

  shortestJob=machines[0][0];
  clrscr();
  printf("%10s","Machine");
  for(col=0;col<5;col++)
    printf("%5d",col);
  printf("\n%-10s\n","Job");
  for(row=0;row<4;row++)
    {
      /* You forgot this line */
      shortestJob=machines[row][0];
      printf("%2d%8s",row,"");
      for(col=0;col<5;col++)
        {
          printf("%5d",machines[row][col]);
          if(machines[row][col] < shortestJob)
            shortestJob=machines[row][col];
        }
      printf("\t%d",shortestJob);
      printf("\n");
    }
  printf("Shortest job is %d",shortestJob);
  return 0;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

chensuCommented:
An expert may be removed from EE by providing answers to school assignments. Check out the agreement.
0
gerrymcdAuthor Commented:
thanks for the ans.  who said this was a school assignmnet. ist part of a program im writting, i just wanted to make sure iwas on the right track.
0
niemeyerCommented:

Well, at this moment I can't read minds Mr Agreement... but some day I get there.

They can remove me if they want to... Maybe then I'll do something more usefull and profitable than wasting my time helping people in exchange for useless points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.