C Program To Check A String Is Palindrome Or Not

C program to check a string is palindrome or not; Through this tutorial, we will learn how to check a string is a palindrome or not using for loop and functions in c programs.

Programs and Algorithm To Check A String Is Palindrome Or Not in C

  • Algorithm to Check a Strng is palindrom or Not
  • C Program To Check A String Is Palindrome Or Not using For Loop
  • C Program To Check A String Is Palindrome Or Not using Function

Algorithm to Check a Strng is palindrom or Not

Use the following algorithm to write to check a whether a given string is palindrome or not; as follows:

  • Start Program
  • Take a string as input and store it in the array.
  • Reverse the string and store it in another array using for loop or function.
  • Compare both the arrays.
  • Print result
  • End Program

C Program To Check A String Is Palindrome Or Not using For Loop

 #include <stdio.h>

#include <string.h>

int main()
{
    char s[1000];
    int i,n,c=0;

    printf("Enter  the string : ");
    gets(s);
    n=strlen(s);

    for(i=0;i<n/2;i++)
    {
    	if(s[i]==s[n-i-1])
    	c++;

 	}
 	if(c==i)
 	    printf("string is palindrome");
    else
        printf("string is not palindrome");



    return 0;
}

The Output of the above c program; as follows:

Enter  the string : hello
string is not palindrome

C Program To Check A String Is Palindrome Or Not using Function

 #include <stdio.h>
#include <string.h>

int checkpalindrome(char *s)
{
    int i,c=0,n;
    n=strlen(s);
	for(i=0;i<n/2;i++)
    {
    	if(s[i]==s[n-i-1])
    	c++;

 	}
 	if(c==i)
        return 1;
    else
        return 0;



 }
int main()
{

    char s[1000];

    printf("Enter  the string: ");
    gets(s);


    if(checkpalindrome(s))
 	    printf("string is palindrome");
    else
        printf("string is not palindrome");



}

The Output of the above c program; as follows:

Enter  the string: madam
string is palindrome

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *