
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- Java Program to Find Sum of Natural Numbers Using While Loop
- Java program to calculate the factorial of a given number using while loop
- Java Program To Reverse A Number And Find the Sum of its Digits Using Do-While Loop
- Java program to print the fibonacci series of a given number using while loop
- do…while loop vs. while loop in C/C++
- Write a C program to reduce any fraction to least terms using while loop
- C program to print number series without using any loop
- C program to print multiplication table by using for Loop
- Find out the GCD of two numbers using while loop in C language
- C Program for Print the pattern by using one loop
- Write a C program to calculate the average word length of a sentence using while loop
- How to use C# do while loop?
- Java Program to print Number series without using any loop
- Java Program to Compute the Sum of Numbers in a List Using While-Loop
- How to create nested while loop in C#?

Advertisements