How to define number palindrome

How to define number palindrome

Mainly the course of programming teaches not rules of use of specific teams, and explains how to shift simple daily tasks to language of algorithms clear to any car. So, a typical problem of this course is writing of the program for finding of number palindrome in language C.

Instruction

1. According to definition, the number palindrome is that if it it is possible is equivalent to read from left to right and from right to left. So, for example, 2002 remains itself even if specularly to reflect it in the opposite direction. Unfortunately, the computer is not able to consider number entirely. The solution of a task will be that the car will consistently compare the first figure to the last, the second from penultimate and further.

2. Define the number of figures in number. Let the user enter number into variable X. Then for determination of number of figures in number it is worth writing a cycle: for (n=0; N

3. Break number into figures. It is possible to make it by means of usual division into 10: having created a cycle which consistently divides X on 10 n time and keeps a remainder of division in in advance prepared massif. For convenience it is possible to fill the massif at once on value n. In order to avoid problems with division make sure that by X it is set tselochislenno (int) of .for (n; n> 0; n-) {A[n] =X%10; X=X10; }

4. Carry out the assessment. Create the cycle comparing values of couples of elements up to the end or until the distinction gets: for (n=0; n

5. When writing the code do not forget to connect math.h library for operation of exponentiation. Besides, add at the end of getch (); that the console was not closed right after end of the program. It is obvious that if you need to find quantity of numbers palindromes in the set range, then operation of check should be repeated cyclically.

Author: «MirrorInfo» Dream Team


Print