Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
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
 2 years ago
 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
 2 years ago
 2 years ago

This Question is Closed

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

milind588Best ResponseYou've already chosen the best response.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
 2 years ago
See more questions >>>
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.