Implementation Code of the number of replies

Source: Internet
Author: User

As the name implies, the return number is a type of number. The forward and reverse reads are completely consistent. For example, 12321,4567654 indicates the number of input files.

It is very easy to use the C language to determine the number of input files. Here, I will give a brief introduction.

First, use a judgment statement. The judgment statement is to find the reverse read data of the number through a loop and a simple operator, and then compare it with itself.

The Code is as follows:

# Include <stdio. h> void main () {int num; scanf ("% d", & num); int min = 0, max = num; while (max> 0) {min = min * 10 + max % 10; max = max/10;} If (min = num) printf ("Number of input files \ n "); else printf ("not the number of replies \ n ");}

The preceding code can be used to determine the number of input records within the int type range. However, if the length exceeds its range, another method is required. Use the string method.

I will not talk about it much, but I will directly look at the code:

# Include <stdio. h> void main () {char STR [100]; scanf ("% s", STR); int I = 0, j = 0; int K = 1; while (STR [J]! = '\ 0') J ++; while (k) {If (STR [I]! = STR [J-1]) {k = 0; printf ("this number is not the number of input! \ N "); break;} if (I = j | j-I = 1) {k = 0; printf (" this number is the number of replies! \ N "); break;} I ++; j --;}}

This program can determine the number of input strings of any length. However, this also has a defect, that is, if the input is not a number, it will also be judged. This is a flaw.

In fact, the number of replies is really simple, so we don't need to write them out. But after all, it is something I learned. let's just use it as a witness to my own learning!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.