C program to check palindrome string or not

List of programs for Checking for palindrome string: c program to check palindrome string or nor using strrev function, c program to check palindrome string or not without strrev function i.e.   c program to check palindrome string or not using arrays,  c program to check palindrome string or not  using pointers,  c program to check palindrome string or not using recursion.

Logic:  find reverse of the string  Now compare the original string with new one, if both are equal the it is a palindrome else the string is not a palindrome.

C program to check palindrome string or not
C program to check palindrome string or not

write a c program to check palindrome string or not using strrev function

write a c program to check palindrome string or not using strrev

#include<stdio.h>
#include<conio.h>
//string.h has built in string function strrev
#include<string.h>
void main()
{
char a[100], b[100];
printf(“To check given string is palindrome or not \n”);
printf(“Enter string \n”);
gets(a);
strcpy(b,a);
// copies string in variable a to variable b
b=strrev(b);
//Reverses string b
if( strcmp(a,b) == 0 )
printf(“Yes, the string is palindrome \n”);
else
printf(” No, the string is not a palindrome \n”);
getch();
}

OUTPUT:

To check  given string is palindrome or not
Enter string: HELLO
No, the string is not a palindrome

write a C program to check palindrome string or not without strrev function

write a c program to check palindrome string or not without strrev function

#include<stdio.h>
#include<conio.h>
void main()
{
char a[30];
int i,j;
int length=0;
boolean check=0;
clrscr();
printf (“To find a given string is palindrome or not “);
printf (“Enter string:\n”);
gets(a);
for(i=0;a[i]!=’\0′;i++)
length++;
i=0;
j=length-1;
while(i<length)
{
if(a[i]!=a[j])
{
check=1;
break;
}
i++;
j–;
}
if(check==0)
printf(“\n The given string is palindrome “);
else
printf(“\n The given string is not a palindrome”);
getch();
}

OUTPUT:

To find a given string is palindrome or not
Enter string: ABCDCBA
The given string is palindrome

write a c program to check palindrome string or not using recursion

write a c program to check palindrome string or not using recursion

#include <stdio.h>
#include <conio.h>
//
#include <string.h>
void main()
{
char str[30];
printf(“C program to check for palindrome string \n”);
printf(“Enter a string \n”);
scanf(“%s”, str);
if(str == ‘\0’)
{
printf(“The entered string is empty \n”);
}
else
{
if(CheckPalindrome(str, 0, strlen(str) – 1))
{
printf(“The given string is a Palindrome \n”);
}
else
{
printf(“The given string is not a Palindrome \n”);
}
}
getch();
}

int CheckPalindrome(char *str, int LeftIndex, int RightIndex)
{
if(LeftIndex>=RightIndex)
{
return 1;
}
if(str[LeftIndex] == str[RightIndex])
{
LeftIndex=LeftIndex+1;
RightIndex=RightIndex-1;
return CheckPalindrome(*str, LeftIndex, RightIndex);
}
return 0;
}

OUTPUT:
C program to check for palindrome string
Enter a string
MOM
The given string is a Palindrome

write a c program that outputs all palindrome strings from list of 10 strings

write a c program that outputs all palindrome strings from list of 10 strings

#include<stdio.h>
#include<conio.h>
//string.h has built in string function strrev
#include<string.h>
void main()
{
char a[10][100], char b[100];
printf(“To find palindrome strings \n”);
for(int i=0;i<10;i++)
{
printf(“Enter string \n”);
gets(a[i]);
}
printf(“The  palindrome strings: “);
int count=0;
for(i=0;i<10;i++)
{
b=strrev(a[i]);
//Reverses string b
if( strcmp(a[i],b) == 0 )
{
printf(” \n %s “, a[i] );
count=count+1;
}
}
if(count==0)
printf(” No palindrome strings exist \n”);
getch();
}

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

Leave a Reply

Your email address will not be published. Required fields are marked *