101 lines
1.0 KiB
C
101 lines
1.0 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int powRec(int x, int n)
|
|
{
|
|
if (n==0)
|
|
{
|
|
return 1;
|
|
}
|
|
else{
|
|
x=x*powRec(x,n-1);
|
|
return x;
|
|
}
|
|
}
|
|
|
|
|
|
int powImp(int x, int n)
|
|
{
|
|
if (n==0)
|
|
{
|
|
return 1;
|
|
}else
|
|
{
|
|
for (int i = 1; i < n; ++i)
|
|
{
|
|
x=x*x;
|
|
}
|
|
return x;
|
|
}
|
|
}
|
|
|
|
void mystere(int n)
|
|
{
|
|
if (n==0)
|
|
{
|
|
/* rien */
|
|
}else
|
|
{
|
|
mystere(n/2);
|
|
printf("%d",n%2);
|
|
}
|
|
}
|
|
|
|
void mystereImp(int n)
|
|
{
|
|
int tab[32];
|
|
int i;
|
|
if (n==0)
|
|
{
|
|
/* rien */
|
|
}else
|
|
{
|
|
for (i = 0; n!=0 ; ++i)
|
|
{
|
|
tab[i]=n%2;
|
|
n=n/2;
|
|
}
|
|
for (int j = i-1; j > -1 ; --j)
|
|
{
|
|
printf("%d",tab[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int iteration=-1;
|
|
|
|
void syracuse2(int n)
|
|
{
|
|
iteration++;
|
|
if (n==1)
|
|
{
|
|
printf("u%d = %d\n",iteration,1);
|
|
}
|
|
else{if ((n%2)==0)
|
|
{
|
|
printf("u%d = %d/2 = %d\n",iteration,n,n/2);
|
|
syracuse2(n/2);
|
|
}else
|
|
{
|
|
printf("u%d = 3*%d+1 = %d\n",iteration,n,(3*n)+1);
|
|
syracuse2((3*n)+1);
|
|
}}
|
|
}
|
|
void syracuse(int n)
|
|
{
|
|
iteration=-1;
|
|
syracuse2(n);
|
|
}
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
/*mystere(5646);
|
|
printf("\n");
|
|
mystereImp(5646);*/
|
|
syracuse(5);
|
|
syracuse(13);
|
|
|
|
return 0;
|
|
} |