Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<math.h>
- int palindrom_zecimal(long int x)
- {
- long int inv = 0, aux = x;
- while (aux > 0)
- {
- inv = inv * 10 + aux % 10;
- aux = aux / 10;
- }
- if (inv == x)
- return 1;
- else
- return 0;
- }
- int palindrom_binar(long int x)
- {
- long long int bit1 = 0, bit2 = 0, j, poz = 1;
- for (j = 0; j <= 31; j++)
- {
- if ((x >> j) & 1)
- {
- bit1 = bit1 * pow(10, poz) + 1;
- poz = 1;
- }
- else
- poz++;
- }
- poz = 1;
- for (j = 31; j >= 0; j--)
- {
- if ((x >> j) & 1)
- {
- bit2 = bit2 * pow(10, poz) + 1;
- poz = 1;
- }
- else
- poz++;
- }
- if (bit1 == bit2)
- return 1;
- else
- return 0;
- }
- int palindrom_octal(long int x)
- {
- long int a[100], k = 1, aux, poz = -1, i;
- while (x > 0)
- {
- poz++;
- a[poz] = x % 8;
- x = x / 8;
- }
- for (i = 0; i <= poz / 2; i++)
- {
- if (a[i] != a[poz - i])
- k = 0;
- }
- return k;
- }
- int palindrom_hexa(long int x)
- {
- int i = 0, poz = -1, k = 1;
- char a[100];
- while (x != 0)
- {
- int temp = 0;
- temp = x % 16;
- if (temp < 10) {
- poz++;
- a[poz] = temp + 48;
- }
- else {
- poz++;
- a[poz] = temp + 55;
- }
- x = x / 16;
- }
- for (i = 0; i <= poz / 2; i++)
- {
- if (a[i] != a[poz - i])
- k = 0;
- }
- return k;
- }
- int main()
- {
- long int n, i, nr, val;
- FILE *fis_in, *fis_out;
- fis_in = fopen("in.txt", "rt");
- fis_out = fopen("out.txt", "wt");
- fscanf(fis_in,"%ld", &n);
- for (i = 10; i <= n; i++)
- {
- nr = 0;
- val = palindrom_zecimal(i);
- nr += val;
- val = palindrom_binar(i);
- nr += val;
- val = palindrom_octal(i);
- nr += val;
- val = palindrom_hexa(i);
- nr += val;
- if (nr >= 2)
- fprintf(fis_out,"%ld\n", i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment