1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

palindrome

Discussion in 'C' started by senthil_a4nlabs, Aug 27, 2016.

  1. senthil_a4nlabs

    senthil_a4nlabs New Member

    Joined:
    Aug 27, 2016
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    give me the program for palindrome
     
  2. persysweb

    persysweb Member

    Joined:
    Aug 1, 2017
    Messages:
    50
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    India
    Home Page:
    Programme for palindrome:

    Code:
    #include <stdio.h>
    int main()
    {
    int n, reversedInteger = 0, remainder, originalInteger;
    printf("Enter an integer: ");
    scanf("%d", &n);
    originalInteger = n;
    while( n!=0 )
    {
    remainder = n%10;
    reversedInteger = reversedInteger*10 + remainder;
    n /= 10;
    }
    
    // palindrome if orignalInteger and reversedInteger are equal
    if (originalInteger == reversedInteger)
    printf("%d is a palindrome.", originalInteger);
    else
    printf("%d is not a palindrome.", originalInteger);
    
    return 0;
    }
    Output:
    Enter an integer: 1001
    1001 is a palindrome.
    Hope this help
    Thanks!
     

Share This Page