Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int _val(int num, int inf, int max);
- int _Quad(float num, int x);
- int _Lenght(int num);
- int main()
- {
- int Input, first, second, temp;
- int tamanho, count, resto;
- int max_cicle, min_cicle;
- int n;
- first = second = tamanho = temp = count = resto = min_cicle = 0;
- n = 0;
- printf("Introduza um Numero par inteiro entre 2 e 8: ");
- scanf("%d", &Input);
- if( ( !_val(Input, 2, 8) && (Input % 2 == 0) ) )
- {
- printf("\n ERRO \n");
- return 0;
- }
- switch(Input)
- {
- case 2: max_cicle = 99; break;
- case 4: max_cicle = 9999; break;
- case 6: max_cicle = 999999; break;
- case 8: max_cicle = 99999999; break;
- }
- tamanho = Input;
- for(;n <= max_cicle;n++)
- {
- if( Input == 2)
- {
- first = n / 10;
- second = n % 10;
- }
- else if( Input == 4)
- {
- first = n / 100;
- second = n % 100;
- }
- else if( Input == 6)
- {
- first = n / 1000;
- second = n % 1000;
- }
- else if( Input == 8)
- {
- first = n / 10000;
- second = n % 10000;
- }
- if( _Quad((first + second), 2) == n )
- printf("\n %d", n);
- }
- printf("\n\n");
- return 0;
- }
- int _val(int num, int inf, int max)
- {
- return (num >= inf && num <= max) ? 1 : 0;
- }
- int _Quad(float num, int x)
- {
- int temp = 1;
- while(x!=0)
- {
- temp*=num;
- x--;
- }
- return temp;
- }
- int _Lenght(int num)
- {
- int resto, x;
- resto = x = 0;
- while( num > 0 )
- {
- resto = num % 10;
- num /= 10;
- x++
- }
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement