Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int enquadrar(double num, int div);
  5. int maiorDivisor(int num);
  6.  
  7. void main(void)
  8. {
  9.    int n, x;
  10.    int origem, destino, quantidade=1;
  11.    printf( "Numero de discos? " );
  12.    scanf( "%d", &n );
  13.    puts( "\n\n" );
  14.    
  15.    for(x=0;x<n;x++)// 2^X
  16.        quantidade*=2;
  17.  
  18.    for (x=1; x < quantidade; x++){
  19.        if(x%2){
  20.             origem = (x-1)%3;
  21.             destino = (x+1)%3;
  22.        }else{
  23.             if(enquadrar(x, 2)){
  24.                 origem=0;
  25.                 destino = (x*2)%3;
  26.             } else {
  27.                 origem=(x-maiorDivisor(x))%3;
  28.                 destino=(x+maiorDivisor(x))%3;
  29.             }
  30.        }
  31.         printf( "%d -- %i||%i.\n", x, origem, destino );
  32.    }
  33.    system("pause");
  34. }
  35.  
  36. int enquadrar(double num, int div)
  37. {
  38.     while(1){
  39.         num/=div;
  40.         if(num==1)
  41.             return 1;
  42.         if(num<1)
  43.             return 0;
  44.     }
  45.     return -1;
  46. }
  47.  
  48. int maiorDivisor(int num){
  49.     int divisor=2;
  50.     while(1){
  51.         if(num%divisor==0)
  52.             divisor*=2;
  53.         else
  54.             return divisor/2;
  55.     }
  56.     return -1;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement