0

for(int x=1;x<=10;x++){ //write a code that counts n return the numbers generated by the loop //eg..10 digits generated by this

c++

23rd Sep 2018, 12:35 PM
Stv Nikto
Stv Nikto - avatar
3 ответов
+ 6
in your sample code, when loop terminates the value of x will be 11 and the numbers generated by loop will be 10. So simply subtract 1 from the value of x and you will your required output. Note that you have declared variable x inside a loop so when you use this variable outside the loop it will give error. So you declare your variable outside the loop. int x; for (x = 1; x <= 10; x++) {} cout << "Digits generated by this loop is: " << x-1 << endl;
23rd Sep 2018, 12:49 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Stv vosti I did not understand your question.
23rd Sep 2018, 12:45 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
thanks..it worked
23rd Sep 2018, 1:00 PM
Stv Nikto
Stv Nikto - avatar