Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

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);

     return 0;
};

Output

Input String: NITIN
NITIN is palindrome.



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib