Wednesday, October 3, 2018

CPL 4 - PALINDROME OR NOT

4. Develop a program to find the reverse of a positive integer and check for palindrome or not. Display appropriate messages.

Algorithm:

ALGORITHM:
Step 1: [read the number N]
     Read N

Step 2: initialize M=N,REV=0

Step 3: [check the value of  N]
        If N is not equal to 0  go to step 4 else go to step 5

Step 4: digit=N%10;
        N=N/10;
    REV=REV*10+digit ;[executes these three steps until N value become 0] 

Step 5: check weather the M=REV if so,go to step 6 else goto step 7

Step 6: Print number is palindrome

Step 7: Print number is not palindrome  

Step 8: Stop.

FLOWCHART:( click on image to zoom )

PROGRAM:

#include<stdio.h>

int main()
{
   int n,m,rev,digit;
   printf("Enter the value of n\n");
   scanf("%d",&n);

   rev=0;
   m=n;
   while(n!=0)
   {
      digit=n%10;
      n=n/10;
      rev=digit+10*rev;
   }
   printf("Reverse of %d is %d\n",m,rev);

   if(m==rev)
     printf("It is a palindrome\n");
   else
     printf("It is not a palindrome\n");
}


OUTPUT:( click on image to zoom )


No comments:

Post a Comment