0
Am I right? for (i=5; i>=1; i--)
#include <iostream> using namespace std; int main(int argc, char *argv[]) { int i, j=1; for (i=5; i>=1; i--) j *= i; cout << j; return 0; } 1st interaction j*=i == j= j*5 so j=5 2nd j = 5*4 so j=20 3rd j = 20*3 so j=60 4th j = 60*2 so j=120 5th j = 120*1 so j=120 Output is 120
5 Answers
+ 1
Yes, you're getting it right Sh.A.kH. đ
If you want to see what happens in each iteration then you can add `cout << j << endl;` inside the loop body. That way each change to <j> will be printed. Don't forget to wrap the loop body block with curly brackets {...}
+ 2
//There is editor in codes Tab where you can run and check.
+ 1
I know about the editor, but do I understand interactions right?
+ 1
Ipang
Wow, thank you! This is the best answer cause sometimes I don't understand outputs but your way can really help me. Thanks !!!!
0
You are welcome Sh.A.kH. đ