+ 1
Program to get the following output
111 121 123 Using for loop only
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;
}
0
Thanks
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
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;
}