Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Tuesday, September 6, 2022

C program to check whether input string is palindrome or not

C program to check whether input string is palindrome or not


#include<stdio.h>

#include<conio.h>

#include<string.h>

main()

{

 char word[30],word1[30];

 printf("Enter any string\n");

 scanf("%s",word);

 strcpy(word1,word);

 if(strcmp(word1,strrev(word))==0)

   {

     printf("%s is palindrome string",word);

   }

   else

    {

    printf("%s is not a palindrome string ",word);

    }

   getch();

 }


Another method:


#include <stdio.h>
#include<conio.h>
#include <string.h>
 
int main()
{
  char s[100];
  int i, len, f;
  f = 0;
 
  printf("Enter any String :  \n");
  gets(s);
 
  len = strlen(s);
     
  for(i = 0; i < len; i++)
{
if(s[i] != s[len - i - 1])
{
f = 1;
break;
}
if(f == 0)
{
printf("%s is a Palindrome String", s);
}
else
{
printf("%s is Not a Palindrome String", s);
}
  getch();
}

Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages