Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Program to Reverse a String and Check Palindrome
✅ C++ Program to Reverse a String and Check Whether It Is a Palindrome
#include <iostream>
#include <string.h>
using namespace std;
void rev(char str[]) {
int start = 0, end = strlen(str) - 1;
int temp;
while (start < end) {
temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end--;
}
}
void pal(char str[]) {
int start = 0, end = strlen(str) - 1;
while (start < end) {
if (str[start] != str[end]) {
cout << "No. String is not palindrome:\n";
return;
}
start++;
end--;
}
cout << "Yes. String is palindrome:\n";
}
int main() {
char str[100];
cout << "Enter the string:\n";
cin.getline(str, 100);
cout << "Before reverse:\n";
cout << str;
cout << "\nAfter reverse:\n";
rev(str);
cout << str << "\n";
pal(str);
}
๐ Explanation:
This program uses two user-defined functions:
rev()— reverses the given string manually by swapping characters from start and end.pal()— checks whether the string is palindrome by comparing characters from both ends.
The program uses cin.getline() to take a string input (including spaces) and strlen() from the string.h library to find string length.
๐งพ Sample Output:
Enter the string: level Before reverse: level After reverse: level Yes. String is palindrome:
๐ Keywords:
C++ palindrome program, reverse string in C++, string manipulation in C++, C++ functions example, palindrome check, character swapping, string length
๐ Hashtags:
#CPlusPlus #String #Palindrome #ReverseString #Programming #CPPBasics
๐ Search Description:
Learn how to reverse a string and check if it is a palindrome using functions in C++. Includes full explanation, sample output, and dark-themed code example.
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment