
- 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
All palindrome numbers in a list?
Here we will see one simple problem. We have to find all numbers that are palindrome in nature in a given list. The approach is simple, take each number from list and check it is palindrome or not, and print the number.
Algorithm
getAllPalindrome(arr, n)
Begin for each element e in arr, do if e is palindrome, then print e end if done End
Example
#include <iostream> #include <cmath> using namespace std; bool isPalindrome(int n){ int reverse = 0, t; t = n; while (t != 0){ reverse = reverse * 10; reverse = reverse + t%10; t = t/10; } return (n == reverse); } int getAllPalindrome(int arr[], int n) { for(int i = 0; i<n; i++){ if(isPalindrome(arr[i])){ cout << arr[i] << " "; } } } int main() { int arr[] = {25, 145, 85, 121, 632, 111, 858, 45}; int n = sizeof(arr) / sizeof(arr[0]); cout << "All palindromes: "; getAllPalindrome(arr, n); }
Output
All palindromes: 121 111 858
- Related Articles
- Palindrome numbers in JavaScript
- Count all palindrome which is square of a palindrome in C++
- Palindrome Linked List in Python
- Print all palindrome permutations of a string in C++
- Python program to multiply all numbers in the list?
- C# program to multiply all numbers in the list
- Count all Palindrome Sub-Strings in a String in C++
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- Python – Test if list is Palindrome
- List all the numbers by rearranging the digits of 1546.
- C++ Program to Generate All Possible Combinations of a Given List of Numbers
- Python Program to Check whether a Singly Linked List is a Palindrome
- Finding the nth palindrome number amongst whole numbers in JavaScript
- JavaScript Program to Check If a Singly Linked List is Palindrome
- Program to find kpr sum for all queries for a given list of numbers in Python

Advertisements