Advertisement
Josif_tepe

Untitled

Dec 23rd, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int proverka_iterativna(char *s) {
  6.     int S = 0;
  7.     int E = strlen(s) - 1;
  8.     while(S <= E) {
  9.         if(*(s + S) != *(s + E)) {
  10.             return 0;
  11.         }
  12.         S += 1;
  13.         E -= 1;
  14.     }
  15.     return 1;
  16. }
  17. int proverka_rekurzivna(char *s, int S, int E) {
  18.     if(S >= E) {
  19.         return 1;
  20.     }
  21.     if(*(s + S) != *(s + E)) {
  22.         return 0;
  23.     }
  24.     return proverka_rekurzivna(s, S + 1, E - 1);
  25. }
  26. //abca
  27. //S  E
  28.  
  29. int main(){
  30.     char s[101];
  31.     scanf("%s", s);
  32.    
  33.     if(proverka_rekurzivna(s, 0, strlen(s) - 1)) {
  34.        
  35.         printf("PALINDROM\n");
  36.     }
  37.     else {
  38.         printf("NE E PALINDROM\n");
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement