Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, December 20, 2014

Program to find given number is palindrome number or not by while loop in C.



Palindrome number checker in C


Code Box
-------------------------------------------

/*Program to find given number is palindrome number or not by while loop in C */

#include<stdio.h>
#include<conio.h>

void main()
{
int num,num1,rem,newnum;
clrscr();

newnum=0;
printf("\n\tPalindrome Number Checker");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number


while(num1>=1)
{
rem=num1%10;
num1=num1/10;
newnum=newnum*10+rem; //Reverse formula
}


if(num==newnum)
{
printf("\nNumber %d is palindrome number ",num);
}
else
{
printf("\nNumber %d is not a palindrome number ",num);
}

getch();

}



--EXPLANATION----------------------------------

To find given number is palindrome or not we need following things to do
  • Create a number reverse formula
  • Find reverse of the given number 
  • Check given number and reverse number are same or not.

this is the simplest way to find that the given number is a palindrome or not.

But this is the human way not for computer. So, you need to convert this strategies into codes.

For doing this we simply follow:
  • Problem understanding done!! as we know the concept of finding palindrome number.
  • Now we need to find variables possible.
  • Logic Building means what are the things we need Like a loop to find reverse, we need to keep given number safe so that we can use it again at end and if else for checking at end. 
 


Now we have every thing concept, variables and logic.
Start writing codes...


  • Take input a number from user
  • reverse it using reverse formula
  • use if else to check input number is equal to reverse number or not
  • print the results.

Here we are using while loop to find reverse of the given number.





If you have any more query or any problem feel free to comment below at codeboxc. we will try to reach you soon with answer.... Learn.Explore.Share!!


No comments: