๐Ÿ’ป
B.TECH I YEAR โ€ข I SEMESTER โ€ข R25

Programming for Problem Solving - Lab Manual

C Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š I Semester ๐Ÿ’ป C Programming ๐Ÿงช Lab Program
Selected Program

Write a C program to determine if the given string is a palindrome or not (Spelled same in both directions with or without a meaning like madam, civic, noon, abcba, etc.).

โ† All Lab Programs

Write a C program to determine if the given string is a palindrome or not (Spelled same in both directions with or without a meaning like madam, civic, noon, abcba, etc.).

C Program
//to find the given string is a palindrome or not.
#include <stdio.h>
#include <string.h>

int main() {
    char str[20];
    int i,j;
    int flag = 0;
    
    printf("Enter a string: ");
    scanf("%s", str);
     // Calculate the string length, -1 for '\0' 
    j=strlen(str)-1;
    // Compare characters from the start and end of the string
    // and stop if a mismatch is found or the middle of the string is reached.
    for(i=0;i<=j;i++,j--)
    {
        if(str[i]!=str[j])
        {
            flag=1;
            break;
        }
    }
     if (flag) {
        printf("%s is not a palindrome\n", str);
    } else {
        printf("%s is a palindrome\n", str);
    }
}

OUTPUT-1
Enter a string: madam
madam is a palindrome
OUTPUT-2
Enter a string: abcdba
abcdba is not a palindrome

๐Ÿ’ป Run This C Program

Write a C program to determine if the given string is a palindrome or not (Spelled same in both directions with or without a meaning like madam, civic, noon, abcba, etc.).
The selected C program is loaded automatically. Edit the code, provide input through STDIN and click Run.

The compiler is embedded using OneCompiler. Your program runs in the embedded C environment; Study Glance does not execute C code directly on your web server.
โ† Back to PPS Lab Programs ๐Ÿ“š All Lab Manuals