 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to find palindrome number by using while loop
Palindrome number is a number which remains same when it reverses. In C language, the user is allowed to enter any positive integer and to check, whether the given number is palindrome number or not by using the while loop.
Example1
Following is the C Program to find Palindrome number by using the while loop −
#include <stdio.h> int main(){    int num, temp, rem, rev = 0;    printf("enter a number:
");    scanf("%d", &num);    temp = num;    while ( temp > 0){       rem = temp %10;       rev = rev *10+ rem;       temp = temp /10;    }    printf("reversed number is = %d
", rev);    if ( num == rev )       printf("
%d is Palindrome Number.
", num);    else       printf("%d is not the Palindrome Number.
", num);    return 0; }  Output
When the above program is executed, it produces the following result −
enter a number: 1234 reversed number is = 4321 1234 is not the Palindrome Number. enter a number: 1221 reversed number is = 1221 1221 is Palindrome Number.
Example2
Consider another example for the C program to find palindrome number by using the while loop for strings.
#include <stdio.h> #include <string.h> void pal(char string[]); int main(){    char string[100];    printf("enter a string: ");    gets(string);    pal(string);    return 0; } void pal(char string[]){    int i = 0;    int length = strlen(string) - 1;    while (length > i){       if(string[i++] != string[length--]){          printf("
 %s is not a palindrome", string);          return;       }    }    printf("
 %s is a palindrome string", string); }  Output
When the above program is executed, it produces the following result −
enter a string: tutorial tutorial is not a palindrome enter a string: saas saas is a palindrome string
Advertisements
 