Check The Given Number Is A Palindrome Number Or Not




Source code :-

#include<stdio.h>
int main()
{
    int n,z,r,s;
    printf("Enter the number: ");
    scanf("%d",&n);
    s=0;
    z=n;
    while(z!=0)   
    {
        r=z%10;
        s=(s*10 )+r;
        z=z/10;
    }
    if(s==n)
        printf("\nThe number is a palindrome number.\n");
    else
        printf("\nThe number is not a palindrome number.\n");
    return 1;
}

Input-Output :- 

abhi@hp-15q-laptop:~$ gcc palindrome.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 121
The number is a palindrome number.

abhi@hp-15q-laptop:~$ gcc palindrome.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 123
The number is not a palindrome number.

Print All The Palindrome Number Of The Given Range

Source code :

#include<stdio.h>
int main()
{
    int n,z,r,s,a,b;
    printf("Enter the lower limit of the range : ");
    scanf("%d",&a);
    printf("\nEnter the upper limit of the range : ");
    scanf("%d",&b);
    printf("\nPalindrome numbers are : ");
    for(n=a;n<=b;n++)
    {
        s=0;
        z=n;
        while(z!=0)   
        {
            r=z%10;
            s=(s*10 )+r;
            z=z/10;   
        }
        if(s==n)
            printf("%d ",s);
    }
    return 1;
}

Input-Output :

abhi@hp-15q-laptop:~$ gcc palindrome.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the upper limit of the range : 10
Enter the lower limit of the range : 100
Palindrome numbers are : 11 22 33 44 55 66 77 88 99

Post a Comment

Previous Post Next Post