Saved Bookmarks
| 1. |
Write a C program that reads a string from keyboard and determines whether the string is palindrome or not. (A string is palindrome if it is read from left or right gives you the same string) |
|
Answer» A C program to check if input string is palindrome or not: #include<stdio.h> #include<conio.h> void main() { int i,j,k,flag=1; char a[20]; clrscr(); printf("enter any word:\n"); scanf("%s",a); i=0; while(a[i]!='\0') i++; k=i; for(j=0;j<k/2;) { if(a[j]!=a[i-1]) { flag=0; break; } if(a[j]==a[i-1]) { j++; i--; } } if(flag==0) printf("it is a not palindrome"); else printf("it is a palindrome"); getch(); } |
|