# Write a c program to check palindrome number

The number is then saved into another variable n to check it when the original number has been reversed. In C we represent boolean values with 1 or 0. Next, the isPalindrome function takes an integer to find reverse as input. Declare recursive function to check palindrome Before we check palindrome numbers using functions, let us first define our function.

If the reversed integer is equal to the integer entered by user then, that number is a palindrome if not that number is not a palindrome. This digit is then added to the rev variable. If the given number is equal to its reverse then the number is palindrome otherwise not.

This number is then compared to the original number n. Here we will use the same recursive approach to find reverse and then will compare the reversed number with original number. Therefore, pass an integer value to the function i. Then, if statement is used to check whether the reversed number is equal to the original number or not.

Simplest programming tutorials for beginners What do you want to learn today? In my previous post I explained how to find reverse of a number recursively. Hence the function must return an integer.

Along with this declare and define another function to find reverse of numbersay int reverse int num. First give a meaningful name to our function, say isPalindrome. Before adding the digit to rev, we first need to multiply the current data in the rev variable by 10 in order to add the digit to the nth place in the number.

The same is done in the code above. Check out these related examples: Finally function must return boolean true or false value based on palindrome condition. Logic to check palindrome number using recursion We know that to check a palindrome number we first need to reverse the number then check whether the given number is equal to its reverse or not.

When the do while loop finally ends, we have a reversed number in rev. This is done easily by multiplying by 10 which gives and adding the number 4, which gives So, to add another number 4 afterwe need to shift the current numbers to the left, so now 1 is in the thousandth place, 2 in the oneth place, 3 is in the onethplace and 4 in the zeroth place.

Considering the above points function declaration to check palindrome number is - int isPalindrome int num .I need to create a program that allows a user to input a string and my program will check to see if that string they entered is a palindrome (word that can be read the same backwards as it can forwards).

C program to check palindrome number using recursion March 8, Pankaj C programming C, Function, Program, Recursion Write a recursive function in C to check palindrome number.

Enter a positive number: The reverse of the number is: The number is a palindrome Enter a positive number: The reverse of the number is: The number is not a palindrome In the above program, use is asked to enter a positive number which is stored in the variable num. Palindrome number in C language: A palindrome number is a which remains the same on reversal. For example, some palindrome numbers are 8,To check whether a number is a palindrome or not first we reverse it and then compare the number obtained with the original number, if both are same then the number is palindrome.

Write a c program to check given string is palindrome number or not Levels of difficulty: Basic / perform operation: Decision and Loops, Frequently Asked C programs in interview, Function, Pointer, Recursion, String. 7. When it becomes zero, using if,else statement check whether the reversed number is equal to original number or not.

8. If it is equal, then print the output as “Number is a palindrome”, otherwise print the output as “Number is not a palindrome”.

Write a c program to check palindrome number
Rated 0/5 based on 77 review
(c)2018