Can anyone explain this code to me?

Help can anyone explain how this code works?

  • hi I was given the answer by the teacher but i still don't know how he got this answer can anyone help me and explain it to me step by step cause i'm not good at programming thank you. this is the answer: {2.2,3.6,7.4,4.2,7.4} and this is the question and the code Consider the following code fragment: double a[] = {7.4,3.6,2.8,4.2,3.9}; double c[] = {2.2,1.0,2.3,1.1,2.4}; int size = 5; int i,j; for(i=size; i>0 ;i--) { for(j=1; j<i; j++) { if(a[j] < a[j-1]) { c[j]=a[j-1]; a[j-1]=a[j]; a[j]=c[j]; } } } After this code is executed what values are stored in the array c? thankyou

  • Answer:

    The easy way is to compile and run the code. If that's not an option, then you can get pencil and paper and walk through the logic step-by-step. Write down the indexing variables, i and j, and keep track of their current values as they're incremented. Also write down the initial contents of arrays a and b, then update them (erase and write new values) as they change.

nobody at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.