Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int isPolindrome(char s[]); //function prototype
  4. main() {
  5. char s[20]; int result;
  6. printf("Enter a string: ");
  7. gets(s); //scanf("%s",s);
  8.  
  9. result = isPolindrome(s); //function call
  10.  
  11. if (result == 1)
  12. printf("polindrome \n");
  13. else printf("NOT polindrome \n");
  14. }
  15.  
  16. int isPolindrome(char s[]) { //function definition
  17. int i,j,l,k;
  18. char rs[20];
  19. j=0; l= 0; //printf("length = %d \n",l);
  20. l= strlen(s);
  21. for(i=l-1;i>=0; i--) { //reversing
  22. rs[j]=s[i]; j++; }
  23. rs[j] ='\0'; //printf("The reversed string = %s \n",rs);
  24.  
  25. if (strcmp(s,rs) == 0) return (1);
  26. else return (0);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement