Hey friends! Give me defination of second loop on my below description and reply me why its sum is 20. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hey friends! Give me defination of second loop on my below description and reply me why its sum is 20.

using namespace std; int main() { int s=0, n=4; cin >> n; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { s += j; } } cout << s; return 0; } //output is 20 but why and how?

15th Aug 2018, 6:12 PM
Albert Whittaker :Shaken To Code
Albert Whittaker :Shaken To Code - avatar
1 Answer
0
add this right under s += j; so you can see whats going on cout << s << i << j;
15th Aug 2018, 6:23 PM
JME