All for Joomla All for Webmasters

Palindrome program in C

Palindrome number in c: A palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers.

Palindrome number algorithm

  • Get the number from user
  • Hold the number in temporary variable
  • Reverse the number
  • Compare the temporary number with reversed number
  • If both numbers are same, print palindrome number
  • Else print not palindrome number

Let’s see the palindrome program in C. In this c program, we will get an input from the user and check whether number is palindrome or not.

  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int n,r,sum=0,temp;
  6. clrscr();
  7. printf(“enter the number=”);
  8. scanf(“%d”,&n);
  9. temp=n;
  10. while(n>0)
  11. {
  12. r=n%10;
  13. sum=(sum*10)+r;
  14. n=n/10;
  15. }
  16. if(temp==sum)
  17. printf(“palindrome number “);
  18. else
  19. printf(“not palindrome”);
  20. getch();
  21. }

Output:

enter the number=151
palindrome  number
enter the number=5621
not palindrome  number
PinIt
submit to reddit

Leave a Reply

Top