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

Problem 4 solution More...

#include <stdio.h>
Include dependency graph for sol.c:

Functions

int is_palindromic (unsigned int n)
 Check if number is palindromic. More...
 
int main (void)
 Main function. More...
 

Detailed Description

Problem 4 solution

Function Documentation

◆ is_palindromic()

int is_palindromic ( unsigned int  n)

Check if number is palindromic.

Parameters
[in]nnumber to check
Returns
1 if palindromic
0 if not palindromic
13{
14 unsigned int reversed = 0, t = n;
15
16 while (t > 0)
17 {
18 reversed = 10 * reversed + (t % 10);
19 t /= 10;
20 }
21 return reversed == n;
22}

◆ main()

int main ( void  )

Main function.

26{
27 unsigned int i, j, max = 0;
28 for (i = 100; i <= 999; i++)
29 {
30 for (j = 100; j <= 999; j++)
31 {
32 unsigned int p = i * j;
33 if (is_palindromic(p) && p > max)
34 {
35 max = p;
36 }
37 }
38 }
39 printf("%u\n", max);
40 return 0;
41}
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
int is_palindromic(unsigned int n)
Check if number is palindromic.
Definition: sol.c:12
Here is the call graph for this function: