Advertisement
niromru

Палиндром

Oct 13th, 2021
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int a, st, ml, ost;
  7.     int pal = 1;
  8.     int len = 0;
  9.     scanf("%d", &a);
  10.     int ac = a;
  11.     while (ac != 0) {
  12.         len++;
  13.         ac /= 10;
  14.     }
  15.     for (int i = 0; i <= (len / 2); i++) {
  16.         ost = pow(10, len - 2 * i - 1);
  17.         st = a / ost;
  18.         ml = a % 10;
  19.         if (st != ml) {
  20.             pal = 0;
  21.             break;
  22.         }
  23.         a = (a - ost * st) / 10;
  24.         if (a == 0) {
  25.             break;
  26.         }
  27.     }
  28.     if (pal == 1) {
  29.         printf("palindrome");
  30.     } else {
  31.         printf("not palindrome");
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement