Advertisement
Aminpro

[ECP1026] In Lab 2, Question 2

Dec 14th, 2012
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. //https://www.facebook.com/AminproPastebin
  2.  
  3.  
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include<stdlib.h>
  7. #include<ctype.h>
  8.  
  9.  
  10.  
  11. int palin(char str[], int offset){
  12.     int ok = 1;
  13.     int length = strlen(str);
  14.     int i;
  15.        
  16.  
  17. for(i=0;i<length;i++){
  18.         str[i]=toupper(str[i]);
  19. }
  20.     if(length/2 > 0)
  21.         ok = (str[0] == str[length - 1 - offset])?
  22.         palin(++str, ++offset):0;
  23.  
  24.     return ok;
  25. }
  26. int main(){
  27.    
  28. while(1){
  29.  
  30.     int i = 0;
  31.     int ok = 0;
  32.     char str[20];
  33.     char ori[20];
  34.    
  35.     printf("Enter a word: ");
  36.     scanf("%s", str);
  37.     strcpy(ori, str);
  38.     ok = palin(str, 0);
  39.        
  40.         switch(ok){
  41.             case 0:
  42.                 printf("%s is not a palindrome.", ori);
  43.                 break;
  44.             case 1:
  45.                 printf("%s is a palindrome.", ori);
  46.                 break;
  47.            
  48.         }
  49.         printf("\n\n");
  50. }
  51.     return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement