+ 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?
1 Respuesta
0
add this right under s += j; so you can see whats going on
cout << s << i << j;