Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 100
  3.  
  4. void main()
  5. {
  6. char str[N],str2[N];
  7. int length;
  8. printf("Enter string 1: ");
  9. gets(str);
  10. printf("The length of the string is %d", stringLength(str));
  11. printf("Enter string 2: ");
  12. gets(str2);
  13. printf("The length of the string is %d", stringLength(str2));
  14. /*length = stringLength(str2);
  15. if (Poly(str, str2, length)==1)
  16. printf("PALINDRUM");
  17. else printf("NOT");
  18. if (longer(str, str2) == 0) printf("Equal length");
  19. else if (longer(str, str2) == 1) printf("First one is longer");
  20. else if (longer(str, str2) == 2) printf("Second one is longer");*/
  21. getch();
  22. return 0;
  23. }
  24. int stringLength(char *str)
  25. {
  26. if (*str == '\0')
  27. return 0;
  28. return 1 + stringLength(str + 1);
  29. }
  30.  
  31. int Poly(char *str1, char *str2, int lastindex)
  32. {
  33. if (lastindex > 0)
  34. {
  35. if (str1[0] != str2[lastindex - 1]) return 0;
  36. else return Poly(str1 + 1, str2, (lastindex-1));
  37. }
  38.  
  39. return 1;
  40. }
  41.  
  42. int longer(char *str1, char *str2)
  43. {
  44. if (str1==NULL&&str2==NULL) return 0;
  45. else if (*str1 != NULL&&*str2 == NULL) return 1;
  46. else if (*str1 == NULL&&*str2 != NULL) return 2;
  47. else return longer(str1 + 1, str2 + 1);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement