Develop a palindrome program in C using loops

Making a palindrome program in C is very easy. You can develop a code using any loop.

If you are not familiar with loops, I am describing for loop syntax below.

For loop syntax

for(initilization; condition; increment/decrement)
statement 1;
statement 2;

initilization is the initial value where your counter value starts 
and condition is the last value.

Palindrome Program in C

void main()
int n,r,b=0,temp;
printf("Enter any number to check palindrome");

tmp=n;//It is copy of number.

printf("Number is Palindrome");
printf("Number is not palindrome");

Program Code Explanation (PCE)

In the above Palindrome Program in C, n is the number entered by a user to check for palindrome number. We assign a new temporary variable temp to store a duplicate copy of n.

We execute a while loop until temp is greater than 0. In this loop, we calculate a reminder(r) value. We have a new variable b which is used to make a reverse number (b=b*10 + r).

Finally, in b we will get a new number if this number is equal to n so the number is palindrome otherwise it is not a palindrome number.

Hope that you understand above program code. Please ask your questions in the comment section below.

Other Programs

Don’t forget to share this program link in your friend’s circle. You can also check our travel blog

Leave a Comment

Show Buttons
Hide Buttons