# C program string palindrome

devquora

Posted On: Jan 26, 2023

### Overview:

In this article First, I want to explain What is a string? Then, I will explain What do you mean by Reverse? and what is positive integer? Moreover, I will explain What is a palindrome? Moreover, I will demonstrate how to check a number is palindrome or not? After all, I will write the logic of a C to check number is palindrome and explain it with output.

### What is a String?

The String is a combination of characters that may be any digit from 0 to 9 and Alphabets from A to Z. The repetition of characters does not matter. For instance, a String Conax uses 5 characters i.e. C,o,n,e,and x.

### What do you mean by Reverse?

Reverse means move backward and turned toward the direction opposite to that previously stated. For instance, If our number is 321 then its reverse string is 123.

### What is a Palindrome string?

A palindrome string is one that reads the same backward as well as forward. It can be of odd or even length. In other words, A Palindrome is an approach in which the reversed string is the same as the previous string. For instance, the Reverse of a number 323 is also 323. So we can say that 323 is a palindrome.

### Logic to check a string, is it palindrome or not

• Step 1: Copy input string into a new string (strcpy function).
• Step 2: Reverse the character of it.
• Step 3: Compare it with the original string (strcmp function).
• Step 4: If both of them have the same sequence of characters, i.e., they are identical, then the string is a palindrome otherwise not.

### C program string palindrome

```#include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
while(1){

printf("Plese! Enter a string to check if it's a palindrome:\n");
gets(a);

strcpy(b, a);  // Copying input string
strrev(b);  // Reversing the string

if (strcmp(a, b) == 0)  // Comparing input string with the reverse string
printf("The string is a palindrome.\n");
else
printf("The string isn't a palindrome.\n");
}
return 0;

}
```

The output of the Program with code:

Conclusion: Explanation of the C program to reverse a string with output.

In the successful compilation of the program, a message is displayed on the screen as Please! Enter a string to check if it's a palindrome:

This program entered a string by user then store it into a variable after that found its reversed and store it in to another variable if both variables are same then we can say that inputed string is palindrome otherwise that is not a palindrome.

Never Miss an Articles from us.

## Related Articles

#### C Program to convert Decimal to Binary Number

A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

#### C program to reverse a string

This program reversed the entered string that means opposite of the previous string sequence...

#### C program to reverse an Integer number

Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..