Answer to Question #3168 in C++ for fmm

Question #3168
What will be the values of k[1] and k[3] after execution of the code segment below using the data shown?

int k[6] = {0, 0, 0, 0, 0, 0};
int i, n;

for (i = 3; i < 6; ++i) {
scanf("%d", &n);
k[n] = i;
}
1
Expert's answer
2011-06-20T14:17:08-0400
This program asks the user enter three values being the indexes for elements of array k, and assigns to elements with these indexes the values 3, 4, 5 respectively.
So for safity it is necessary to enter numbers from 0 to 5.

Thus the values of k[1] and k[3] depend on indexes which the user enter.
For example
if the user input 0,1,2 then k[1]=4, k[3]=0
if the user input 3,2,4 then k[1]=0, k[3]=3
if the user input 5,0,3 then k[1]=0, k[3]=5

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS