Paradoxul NR 6174

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <iostream>

using namespace std;


long long int n, i, a[13], j, r, x, y, l=1, k=0, m=0, t, p, c=0;
int main()
{
do
{
cout <<"dati un numar=";
cin >>n;
if (n<10000 && n>999)
{
t=n;
l=1;
while (t!=0)
{
a[l++]=t%10;
t=t/10;
}
for (i=1;i<4 && k==0;i++)
{
if (a[i]!=a[i+1])
k=1;
}
}
}while (k==0);

while(n!=6174)
{
for (i=1;i<4;i++)
{
for (j=i+1;j<=4;j++)
{
if (a[i]>a[j])
{
r=a[i];
a[i]=a[j];
a[j]=r;
}
}
}
x=y=0;
for (i=1;i<=4;i++)
{
x=x*10+a[i];
y=y*10+a[5-i];
}
cout <<x<<" "<<y<<"\n";
n=y-x;
if (n<1000)
n=n*10;
p=n;
c++;
l=1;
while (p!=0)
{
a[l++]=p%10;
p=p/10;
}
}
cout<<c;

return 0;
}

You might also like