top of page

C Program to Check if a Given String is Palindrome

Updated: Jul 10, 2020

In this program, we will learn how to check the given string is palindrome or not.

For Example- A string is said to be palindrome if the reverse of the string is the same as string.

For example,

Input − naman 

Output − string is a palindrome 


Input − ProgrammerDoor

Output − string is not a palindrome



 

Implementation:

#include <iostream>
#include<string.h>
using namespace std; {
   int main(){
      char string1[]={"naman"};
      int i, length;
      int flag = 0;
      length = strlen(string1);
      for(i=0;i < length ;i++){
         if(string1[i] != string1[length-i-1]) {
            flag = 1;
            break;
         }
      }
      if (flag==1){
         printf(" string is not a palindrome");
      } else {
         printf("string is palindrome");
      }
     return 0;
   }
}

Output :

string is a palindrome
14 views0 comments

Recent Posts

See All
bottom of page