A community for students.
Here's the question you clicked on:
 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
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

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0do you understand how the loops work? simply follow the program along using the numbers given for a[8]

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0see 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
Ask your own question
Sign UpFind 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
 Engagement 19 Mad Hatter
 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.