Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
30. Write a program in C to check whether the given string is a palindrome or not.
/*
File: Prgrm30.c
Author: Aditya Saini
Date: Jan 18, 2021
Description: Program to check whether the given string is a palindrome or not.
*/
#include <stdio.h>
#include <string.h>
int main (void)
{
char str[20];
char revstr[20];
//Input string
printf ("Input String: ");
gets (str);
//Copy and Reverse string
strcpy (revstr, str);
strrev (revstr);
//Check if the string is palindrome or not and print result
if (strcmp (str, revstr))
printf ("%s is not palindrome.", str);
else
printf ("%s is palindrome.", str);
};
Output
Input String: NITIN
NITIN is palindrome.
No comments:
Post a Comment
Please do not post spam links.