C program for palindrome numbers and string

Palindrome number is who's reverse number is equal to that number is called palindrome number. For example 151 because its reverse no. is 151. Same with the string. A string is equal to its reverse string. For example saras is equal to its reverse saras.

C program to check number is palindrome or not



#include<stdio.h>

void main()
{
       int no,no1,rem,rev=0;
       clrscr();

       printf("Enter no::");
       scanf("%d",&no);
       no1=no;

       while(no>0)
       {
              rem=no%10;
              rev=rev*10+rem;
              no=no/10;
       }

       if(no1==rev)
       {
              printf("No is palindrom");
       }
       else
       {
              printf("No. is not palindrom");
       }

       getch();
}

c program for palindrome numbers


C program to check string palindrome or not

#include<stdio.h>

void main()
{
       char str[50];
       int i,count,flag;
       clrscr();
       count=0;
       flag=0;

       printf("Enter any string::");
       gets(str);

       for(i=0;str[i]!='\0';i++)
       {
              count++;
       }

       count=count-1;
       for(i=0;i<=count/2;i++)
       {
              if(str[i]==str[count])
              {
                     flag=0;
              }
              else
              {
                     flag=1;
                     break;
              }
              count--;

       }

       if(flag==0)
       {
              printf("String is palindrom");
       }
       else
       {
              printf("String is not palindrom");
       }
       getch();
}


c program for palindrome numbers and string

0 comments:

Post a Comment