Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 100
- void main()
- {
- char str[N],str2[N];
- int length;
- printf("Enter string 1: ");
- gets(str);
- printf("The length of the string is %d", stringLength(str));
- printf("Enter string 2: ");
- gets(str2);
- printf("The length of the string is %d", stringLength(str2));
- /*length = stringLength(str2);
- if (Poly(str, str2, length)==1)
- printf("PALINDRUM");
- else printf("NOT");
- if (longer(str, str2) == 0) printf("Equal length");
- else if (longer(str, str2) == 1) printf("First one is longer");
- else if (longer(str, str2) == 2) printf("Second one is longer");*/
- getch();
- return 0;
- }
- int stringLength(char *str)
- {
- if (*str == '\0')
- return 0;
- return 1 + stringLength(str + 1);
- }
- int Poly(char *str1, char *str2, int lastindex)
- {
- if (lastindex > 0)
- {
- if (str1[0] != str2[lastindex - 1]) return 0;
- else return Poly(str1 + 1, str2, (lastindex-1));
- }
- return 1;
- }
- int longer(char *str1, char *str2)
- {
- if (str1==NULL&&str2==NULL) return 0;
- else if (*str1 != NULL&&*str2 == NULL) return 1;
- else if (*str1 == NULL&&*str2 != NULL) return 2;
- else return longer(str1 + 1, str2 + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement