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
Related Q & A:
- Can anyone give me the code for toshiba tv with the URC22B?Best solution by Yahoo! Answers
- Can anyone explain this dream to me?Best solution by Yahoo! Answers
- Can anyone help me get the code for my stereo?Best solution by Yahoo! Answers
- Can anyone suggest how I can improve myself?Best solution by Yahoo! Answers
- Can anyone help with a code for a ford fiesta radio?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.