Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

maram

  • 4 years ago

What is the output of the following section of a program? int a[8] = {6, 3, 7, 4, 4, 5, 3, 2, 5 }; int b=a[0], c=0; for(int i=0;i<8;i++) if(a[i]<b){ b=a[i]; c=i; } cout<<c<<” “a[c]<<endl; answer should be: 7 and 2 but how come

  • This Question is Closed
  1. tdabboud
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    do you understand how the loops work? simply follow the program along using the numbers given for a[8]

  2. milind588
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    see when in the loop value of i becomes 7 , it tests +ive for the condition that a[7] i.e 5 is smaller then 6 , it goes inside the for loop now c=i i.e c=7 and a[c] ie a[7] inthe array is 2 thus the outputs will be 7 and 2

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy