I created some code where, whenever you put number in pinCombo(x)
(for example pinCombo(3)
), the output will be:
000
001
002
… until it reaches 999.
So, pinCombo(4)
output will be:
0000
0001
....
....
9999
Here's my code:
#include <iostream>
using namespace std;
void pinCombo(int x)
{
int a,b,c,d,e,f,g,h,i,j;
if(x>=1)
for (a = 0;a<10;a++)
{
if(x>=2)
for (b = 0;b<10;b++)
{
if(x>=3)
for (c = 0;c<10;c++)
{
if(x>=4)
for (d = 0;d<10;d++)
{
if(x>=5)
for (e = 0;e<10;e++)
{
if(x>=6)
for (f = 0;f<10;f++)
{
if(x>=7)
for (g = 0;g<10;g++)
{
if(x>=8)
for (h = 0;h<10;h++)
{
if(x>=9)
for (i = 0;i<10;i++)
{
if(x>=10)
for (j = 0;j<10;j++)
{
cout<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<endl;
}if(x==9)cout<<a<<b<<c<<d<<e<<f<<g<<h<<i<<endl;
}if(x==8)cout<<a<<b<<c<<d<<e<<f<<g<<h<<endl;
}if(x==7)cout<<a<<b<<c<<d<<e<<f<<g<<endl;
}if(x==6)cout<<a<<b<<c<<d<<e<<f<<endl;
}if(x==5)cout<<a<<b<<c<<d<<e<<endl;
}if(x==4)cout<<a<<b<<c<<d<<endl;
}if(x==3)cout<<a<<b<<c<<endl;
}if(x==2)cout<<a<<b<<endl;
}if(x==1)cout<<a<<endl;
}
}
using namespace std;
int main()
{
pinCombo(3);
return 0;
}
Is there a way to create a program like this without using nested loops or without using many variables?