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 check if a given string is a palindrome or not using a custom function
๐ Palindrome Check in C (Using Custom Function)
#include<stdio.h>
#include<string.h>
void pal(char str[])
{
int left = 0, right = strlen(str) - 1;
while (left < right)
{
if (str[left] != str[right])
{
printf("No, Entered string is not palindrome:\n");
return;
}
left++;
right--;
}
printf("Yes, Entered string is palindrome:\n");
}
int main()
{
char str[100];
printf("Enter the string:\n");
scanf("%[^\n]", str);
pal(str);
}
๐ Explanation:
๐น The function `pal()` compares characters from the start and end moving toward the center.
๐น If a mismatch is found, the string is not a palindrome.
๐น The `scanf("%[^\n]", str)` reads a full line including spaces.
๐น This logic is case-sensitive and does not ignore spaces or punctuation.
๐งช Sample Output:
Enter the string:
madam
Yes, Entered string is palindrome:
Enter the string:
hello
No, Entered string is not palindrome:
๐ท️ Keywords:
C palindrome program, check palindrome in C, string comparison, string reverse logic, C interview program, custom function for palindrome check
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