Showing posts with label Palindrome. Show all posts
Showing posts with label Palindrome. Show all posts

Write a c program to check given string is palindrome number or not.

How to Write a c program to check given string is palindrome number or not.


#include<string.h>
#include<stdio.h>
int main(){
  char *str,*rev;
  int i,j;
  printf("\nEnter a string:");
  scanf("%s",str);
  for(i=strlen(str)-1,j=0;i>=0;i--,j++)
      rev[j]=str[i];
      rev[j]='\0';
  if(strcmp(rev,str))
      printf("\nThe string is not a palindrome");
  else
      printf("\nThe string is a palindrome");
  return 0;
}

C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not

How to write a C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not in C Programming Language ?


Solution For C Program :

/*C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not.*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,length=0,flag;
char str[10],rev[10];
clrscr();
printf("Enter the string==>");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",str,length);
length--;
for(i=0;length>=0;i++)
{
 rev[i]=str[length];
 length--;
}
rev[i]='\0';
printf("\nReverse of %s is ==>%s\n",str,rev);

 length++;
for(i=0;rev[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",rev,length);

for(i=0;str[i]!='\0'||rev[i]!='\0';i++)
{
if(str[i]!=rev[i])
    {
    flag=1;
    break;
    }
}
if(flag==1)
printf("\nString is not polyndrom");
else
printf("\nString is polyndrom");
getch();
}

C Program To Check If It Is A Palindrome Numbers Or Not

How to write a C Program To Check If It Is A Palindrome Numbers Or Not in C Programming Language ?

Solution:

C Program To Check If It Is A Palindrome Numbers Or Not

#include<stdio.h>

main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}