Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
palindrome.c File Reference

Program to identify if a number is palindrome number or not. More...

#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
Include dependency graph for palindrome.c:

Functions

bool isPalindrome (int number)
 Check given number whether is palindrome number or not.
 
int main ()
 Driver Code.
 

Detailed Description

Program to identify if a number is palindrome number or not.

See also
project_euler/problem_4/sol1.c

Function Documentation

◆ isPalindrome()

bool isPalindrome ( int  number)

Check given number whether is palindrome number or not.

Parameters
numbernumber to check
Returns
true if given number is palindrome number
false if number is not a palindrome number
30{
31 int reversedNumber = 0;
32 int originalNumber = number;
33 while (number != 0)
34 {
35 int remainder = number % 10;
36 reversedNumber = reversedNumber * 10 + remainder;
37 number /= 10;
38 }
39 return originalNumber == reversedNumber;
40}

◆ main()

int main ( void  )

Driver Code.

15{
16 assert(isPalindrome(0));
17 assert(isPalindrome(1));
18 assert(isPalindrome(12321));
19 assert(!isPalindrome(1234));
20 return 0;
21}
bool isPalindrome(int number)
Check given number whether is palindrome number or not.
Definition: palindrome.c:29
Here is the call graph for this function: