21st Aug 2020, 2:22 AM
Aya Khalid
Aya Khalid - avatar
10 Answers
+ 4
What output you expecting through this program After for loop you wrote a=7 it working infinite times . but if u enter Big number which is more than 10 then its working one time becoz condition false and a++ it will increase value by 1 . may be you want to print Numbers like 0,1,2,3.....9 #include <iostream> using namespace std; int main() { int a; for( a=0;a<10;a++)cout<<a<<endl; return 0; }
21st Aug 2020, 4:48 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
https://code.sololearn.com/c53bHjySP7Kd/?ref=app I solved your problem see in the code. Where you entered a<10 then entered a=7 Please put a= 10,11,or 12...........
21st Aug 2020, 2:40 AM
Sunny Khartode
Sunny Khartode - avatar
+ 1
https://code.sololearn.com/c4JEqqrE0s6E/?ref=app Or while replacing a<10 to a>10 then output will be 0 try it Solved in 👆 in code
21st Aug 2020, 2:43 AM
Sunny Khartode
Sunny Khartode - avatar
+ 1
#include <iostream> using namespace std; int main() { int a; for( a=0;a<10;a++){ a=7; cout<<a<<endl; } return 0; }
21st Aug 2020, 4:28 AM
Akash Agrawal
Akash Agrawal - avatar
+ 1
What are you wanna do the code ? Is it like this or something like that :) for(int a =0;a<10;a++){ if (a == 7 ) cout << a<< endl; }
21st Aug 2020, 12:28 PM
Naveed
Naveed - avatar
0
7
21st Aug 2020, 2:26 AM
Aya Khalid
Aya Khalid - avatar
0
Why it's infinite? There is (a++)in the loop so,it would make it finite.
21st Aug 2020, 2:30 AM
Aya Khalid
Aya Khalid - avatar
0
Replace trailing ';' at row 6 (the loop line) with ',' this way you will see output and what is happening
21st Aug 2020, 6:00 AM
Bilbo Baggins
Bilbo Baggins - avatar
0
The variable a, every time the loop acts, it becomes 7 again as a value, so the loop is infinite, also, after the loop you should use curly braces for its function. include <iostream> using namespace std; int main() { int a; for( a=0;a<7; a++) { } cout<<a<<endl; return 0; }
21st Aug 2020, 7:10 AM
Reginmund Morales
Reginmund Morales - avatar