Here's the question you clicked on:
maram
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
do you understand how the loops work? simply follow the program along using the numbers given for a[8]
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