60 688
Assignments Done
97,9%
Successfully Done
In April 2018

Answer to Question #3167 in C++ for fmm

Question #3167
What is output of the following:

k = 0;
m = 0;
for (p = 0; p < 10; p = p + k) {
k = k + 1;
m = m + p;
printf("%d %d %d\n", p, k, m);
}
Expert's answer
1st loop,& p=p+k=0+0=0<10:
k=k+1=0+1=1 m=m+p=0+0=0
2nd loop, p=p+k=0+1=1<10:
k=k+1=1+1=2 m=m+p=0+1=1
3rd loop, p=p+k=1+2=3<10:
k=k+1=2+1=3 m=m+p=1+3=4
4th loop, p=p+k=3+3=6<10:
k=k+1=3+1=4 m=m+p=4+6=10
5th loop: p=p+k=6+4=10, that`s all, condition is not satisfied, so output is

0& 1 & 0
1& 2 1
3& 3 4
6& 4 10

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions