Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

maram

  • 2 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
    • 2 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
    • 2 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

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.