This is a C program to check a given string is palindrome without using the Built-in Function.
This program accepts a string and checks whether a given string is palindrome without using the built-in function.
1. Take a string as input and store it in the array.
2. Reverse the string and store it in another array.
3. Compare both the arrays.
Here is source code of the C program to check a given string is palindrome without using the Built-in Function .The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C program to find the length of a string without using the
* built-in function also check whether it is a palindrome
*/
#include <stdio.h>
#include <string.h>
void main()
{
char string[25], reverse_string[25] = {'\0'};
int i, length = 0, flag = 0;
printf("Enter a string \n");
gets(string);
/* keep going through each character of the string till its end */
for (i = 0; string[i] != '\0'; i++)
{
length++;
}
printf("The length of the string '%s' = %d\n", string, length);
for (i = length - 1; i >= 0 ; i--)
{
reverse_string[length - i - 1] = string[i];
}
/* Check if the string is a Palindrome */
for (flag = 1, i = 0; i < length ; i++)
{
if (reverse_string[i] != string[i])
flag = 0;
}
if (flag == 1)
printf ("%s is a palindrome \n", string);
else
printf("%s is not a palindrome \n", string);
}
1. Take a string as input and store it in the array string[].
2. Store the same string into the another array reverse_string[] in the reverse fashion.
3. Using for loop compare the elements of both the arrays.
4. If all the elements of the array are same, then it is a palindrome. Otherwise it is not a palindrome.
Enter a string how are you The length of the string 'how are you' = 12 how are you is not a palindrome Enter a string madam The length of the string 'madam' = 5 madam is a palindrome Enter a string mam The length of the string 'mam' = 3 mam is a palindrome
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Apply for C Internship