Monday, January 11, 2016

To check given number is Palindrome or not.

 Object: - Write a  program and algorithm to check given number is Palindrome or not. 
 

Algorithm-
 Step (1):- Start
Step (2):- Declare the variable n, r, p, temp. 
Step (3):- initialize p = 0  
Step (4):- “Enter the number”
Step (5):- temp ← n

Step (6):- while (n > 0)
(6.1) r=n%10
(6.2) p=p*10+r
(6.3) n=(n/10)
(6.4) end while loop

Step (7):- if (temp = = p)
(7.1) Given no is palindrome

Step (8):- else
(8.1) Given no is not palindrome

Step (9):- Stop.

Program:-

# include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n, r, p=0, temp;
printf("Enter the number:");
scanf("%d",&n);
temp=n;
while (n>0)
{
r=n%10;
p=p*10+r;
n=n/10 ;
}
if(temp==p)
{
printf("Given no is palindrome");
}
else
{
printf("Given no is not palindrome");
}
getch();
}

Output:-
------------------------------------------------------------------------

Enter the number:151
Given no is palindrome

0 Comments:

Post a Comment