+ 1

Program to get the following output

111 121 123 Using for loop only

4th Nov 2016, 3:11 PM
Aditya
4 Answers
+ 6
#include <iostream> using namespace std; int main() { int i,j; for(i=1;i<=3;i++){ for(j=1;j<=i;j++){ cout<<j; } for(j=i+1;j<=3;j++) cout<<"1"; cout<<endl; } return 0; }
4th Nov 2016, 4:10 PM
kamal joshi
kamal joshi - avatar
0
Thanks
4th Nov 2016, 4:13 PM
Aditya
0
#include <iostream> using namespace std; int main() { int i,j,o; for(i=1;i<2;i++) { for(j=1;j<3;j++) { for(o=j;o<j+2;o++) { j=(j==2)?j+1:j; cout << i << o << j << endl; if(j==3) break; } } } return 0; } can I use if and ternary operator
5th Nov 2016, 3:58 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
#include <iostream> using namespace std; int main() { int i,j,o; for(i=1;i<2;i++) { for(j=1;j<3;j++) { cout << i << j << i << endl; } } for(i=1;i<4;i++) cout << i; return 0; }
5th Nov 2016, 4:36 AM
Aditya kumar pandey
Aditya kumar pandey - avatar