Advertisement
FoxTuGa

Quad igual a Soma

May 8th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int _val(int num, int inf, int max);
  4. int _Quad(float num, int x);
  5. int _Lenght(int num);
  6.  
  7. int main()
  8. {
  9.     int Input, first, second, temp;
  10.     int tamanho, count, resto;
  11.     int max_cicle, min_cicle;
  12.     int n;
  13.     first = second = tamanho = temp = count = resto = min_cicle = 0;
  14.     n = 0;
  15.     printf("Introduza um Numero par inteiro entre 2 e 8: ");
  16.     scanf("%d", &Input);
  17.     if( ( !_val(Input, 2, 8) && (Input % 2 == 0) ) )
  18.     {
  19.         printf("\n ERRO \n");
  20.         return 0;
  21.     }
  22.  
  23.     switch(Input)
  24.     {
  25.     case 2: max_cicle = 99; break;
  26.     case 4: max_cicle = 9999; break;
  27.     case 6: max_cicle = 999999; break;
  28.     case 8: max_cicle = 99999999; break;
  29.     }
  30.  
  31.     tamanho = Input;
  32.     for(;n <= max_cicle;n++)
  33.     {
  34.         if( Input == 2)
  35.         {
  36.             first = n / 10;
  37.             second = n % 10;
  38.         }
  39.         else    if( Input == 4)
  40.         {
  41.             first = n / 100;
  42.             second = n % 100;
  43.         }
  44.         else    if( Input == 6)
  45.         {
  46.             first = n / 1000;
  47.             second = n % 1000;
  48.         }
  49.         else    if( Input == 8)
  50.         {
  51.             first = n / 10000;
  52.             second = n % 10000;
  53.         }
  54.        
  55.         if( _Quad((first + second), 2) == n )
  56.             printf("\n %d", n);
  57.     }
  58.        
  59.     printf("\n\n");
  60.     return 0;
  61. }
  62.  
  63. int _val(int num, int inf, int max)
  64. {
  65.     return (num >= inf && num <= max) ? 1 : 0;
  66. }
  67.  
  68. int _Quad(float num, int x)
  69. {
  70.     int temp = 1;
  71.     while(x!=0)
  72.     {
  73.         temp*=num;
  74.         x--;
  75.     }
  76.     return temp;
  77. }
  78. int _Lenght(int num)
  79. {
  80.     int resto, x;
  81.     resto = x = 0;
  82.     while( num > 0 )
  83.     {
  84.         resto = num % 10;
  85.         num /= 10;
  86.         x++
  87.     }
  88.     return x;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement