Calculates the number of times a number appears in a value range and the number of times a value range appears.

Source: Internet
Author: User

Calculates the number of times a number appears in a value range and the number of times a value range appears.

Calculates the number of times a number 9 appears in a numerical range.


1. Program Implementation

2. Function Testing

3 program optimization

4. Add debugging code


··············

1. Program Implementation

Vim 9.c

Gcc 9.c

./A. out

The image is too large. Change the number of columns to 10.


2. Function Testing

Test whether the 9 value in a number can be accurately determined.

Modify:

Min = 9938;

Max = 9939;

......

./A. out

Display num: 9 in 9938 and 9939.

There are.

| 9938 9939

From 9938 to 9939 have num 9 is: 5


3 program optimization

Learn a piece of code from the experts and make a modification record.

While (jj)

{

If (j = ii % 10)

K ++;

// Ii = (ii-ii % 10)/10;

// If (ii <jj)

// Jj = 0;

Ii = ii/10;

If (ii = ii/10)

Jj = 0;

}


4. Add debugging code

Add the debugging code and modify the code as follows: (the original Lines 18 and 51; add line "well)

# If t

Printf ("Display num: % d in % d and % d. \ n \ tThere are. \ n \ t |", j, min, max );

# Endif

# If t

Printf ("% 6d", I );

# Endif


Compile:

Gcc 9.c-Dt-o 1
Gcc 9.c-Ut-o 2


./1

Display num: 9 in 9938 and 9939.

There are.

| 9938 9939

From 9938 to 9939 have num 9 is: 5


./2


From 9938 to 9939 have num 9 is: 5

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.