Write a C program to determine if the given string is a palindrome
(or) not.
Algorithm:
Step 1: Start Step 2: read the string Step 3: store reverse of the given string in a temporary string Step 4: compare the two strings Step 5: if both are equal then print palindrome Step 6: otherwise print not palindrome Step 7: Stop
Program:
#include <stdio.h> #include <conio.h> #include <string.h> void main() { char str[20]; int i, l, f = 0; clrscr(); printf("Enter any string\n"); gets(str); l = strlen(str); for(i = 0; i <= l - 1; i++) { if(str[i] == str[l - 1 - i]) f = f + 1; } if(f == l) { printf("The string is palindrome"); } else { printf("The string is not a palindrome"); } getch(); }
Input & Output:
Enter any string malayalam The string is a palindrome
-
UpdatedDec 25, 2014
-
Views12,650
You May Like
Write a C program to find the roots of a quadratic equation
.
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use switch statement
)
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write C programs that use both recursive
and non-recursive functions
- To find the
factorial
of a given integer. - To find the
GCD
(greatest common divisor) of two given integers.