Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int enquadrar(double num, int div);
- int maiorDivisor(int num);
- void main(void)
- {
- int n, x;
- int origem, destino, quantidade=1;
- printf( "Numero de discos? " );
- scanf( "%d", &n );
- puts( "\n\n" );
- for(x=0;x<n;x++)// 2^X
- quantidade*=2;
- for (x=1; x < quantidade; x++){
- if(x%2){
- origem = (x-1)%3;
- destino = (x+1)%3;
- }else{
- if(enquadrar(x, 2)){
- origem=0;
- destino = (x*2)%3;
- } else {
- origem=(x-maiorDivisor(x))%3;
- destino=(x+maiorDivisor(x))%3;
- }
- }
- printf( "%d -- %i||%i.\n", x, origem, destino );
- }
- system("pause");
- }
- int enquadrar(double num, int div)
- {
- while(1){
- num/=div;
- if(num==1)
- return 1;
- if(num<1)
- return 0;
- }
- return -1;
- }
- int maiorDivisor(int num){
- int divisor=2;
- while(1){
- if(num%divisor==0)
- divisor*=2;
- else
- return divisor/2;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement