Risonna

lab2_n7

Oct 27th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int s, n, n1, n2, n3, s1, s2, s3, s4;
  8.     cout << "Введите число --> "; cin >> n;
  9.     s1 = n % 10;
  10.     n1 = n / 10;
  11.     s2 = n1 % 10;
  12.     n2 = n / 100;
  13.     s3 = n2 % 10;
  14.     n3 = n / 1000;
  15.     s4 = n3 % 10;
  16.     if (n <= 9999 && n>0)
  17.     {
  18.         if (n >= 1000)
  19.         {
  20.             if (s1==s4 && s3==s2)
  21.             {
  22.                 cout << "Является палиндромом\n";
  23.             }
  24.             else
  25.             {
  26.                 cout << "Палиндромом не является\n";
  27.             }
  28.         }
  29.         else
  30.         {
  31.             if (n >= 100)
  32.             {
  33.                 s = n % 10;
  34.                 n = n / 100;
  35.                 if (s == n)
  36.                 {
  37.                     cout << "Является палиндромом\n";
  38.                 }
  39.                 else
  40.                 {
  41.                     cout << "Палиндромом не является\n";
  42.                 }
  43.             }
  44.             else
  45.             {
  46.                 s = n % 10;
  47.                 n = n / 10;
  48.                 if (s == n)
  49.                 {
  50.                     cout << "Является палиндромом\n";
  51.                 }
  52.                 else
  53.                 {
  54.                     cout << "Палиндромом не является\n";
  55.                 }
  56.             }
  57.         }
  58.     }
  59.     else
  60.     {
  61.         cout << "n не соответствует условиям\n";
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment