Skip to main content

Posts

Showing posts from August, 2014

A Palindrome program in c language

 c code to check if a string is a palindrome or not and for palindrome number. The first step we copy the entered string into a new string, and then we reverse the new string and then compares it with original string. If both of them have same sequence of characters i.e. they are identical then the entered string is a palindrome otherwise  not palindrome.Some palindrome strings examples are  “ dad “, “ radar “, “ madam ” etc. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int i=0,j=0,k=0; char *str; char *s; clrscr(); printf("Program to find whether the given string and it's reverse are same\n\n"); printf("Enter the length of the string\n"); scanf("%d",&j); str=(char*)malloc((j+1)*sizeof(char)); s=(char*)malloc((j+1)*sizeof(char)); fflush(stdin); printf("Enter the string\n"); gets(str); for(i=0;i<j;i++) { *(s+i)=*(str+(j-1-i)); //printf("Character %d of Original strin