The basics of programming in c++ for beginners

A task: Palindrome array

Check the number in the array for the presence of palindrome (it is through an array).

with the solution of the problem, palindrom, the presence of a palindrome in the array c ++, the number of palindrome, programming practice
Determination palindrome – website wikipedia

Decision:

The only place, which code may cause difficulty, is a logical assignment:

There is verified characters equality, otstoyashtih of i position from the beginning of the end of the study line. If the result is negative (not equal), then it is not a palindrome, and can leave the cycle, and further comparison is not carried out. Variable poli here it is not necessary, and left for clarity – you can make a decision (if) directly from the checked conditions.

Checks are made until the middle strings, because the further continuation of the cycle (due to the symmetry conditions) Only then will repeat, what has been done previously.

Performance:

with the solution of the problem, palindrom, the presence of a palindrome in the array c ++, the number of palindrome, programming practiceNote:

As can easily be noted observational readers, This code will check on the palindrome is not only a record number, but any text string, when these conditions are met:

    • row contains only Latin (not Russians, not Chinese, …) letters (international letters into Unicode seem to be more than the 1st byte);
    • line does not contain blank spaces and punctuation marks (because the definitions of these symbols are palindromes, usually, excluded from the comparisons: “I ydu courts with sword“, “On the forehead, blockhead“).

5 thoughts on “A task: Palindrome array

  1. Error code. All the two-digit numbers, for example: 11, 22, 33, …, 99 the program recognizes both “not palindromes”, although it is not so. The code needs to be improved.

    1. no error! Here check runs in the operating system Linux with GCC compiler, which is much more representative of the standard C ++ syntax:

      $ ./palindrom-
      Введите любое положительное целое : 11
      число палиндром
      Введите любое положительное целое : 2
      число палиндром
      Введите любое положительное целое : 232
      число палиндром
      Введите любое положительное целое : 233
      число не палиндром
      Введите любое положительное целое : 2332
      число палиндром
      Введите любое положительное целое : 23432
      число палиндром
      Введите любое положительное целое : 234432
      число палиндром
      Введите любое положительное целое : ^C

      I do not know, why you have obtained the following results (You may need to arrange additional brackets for priority operations).

  2. Trading company "Vostok" at the end of each month sums up the results, that is, it enters the book of expenses and sales proceeds. Will compose a program to calculate the amount of income received for each quarter and determine in which quarter the minimum income was received.

Leave a Reply

Your email address will not be published. Required fields are marked *