Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to program in C language to count the number 9 in all integers from 1 to 100

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to write a program in c language to count the number 9 in all integers from 1 to 100, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

Idea: to determine the number of times 9 appears in an integer, each bit of the integer can be put forward in turn to determine whether it is 9.

Method: for a single digit, the remainder of 10 is itself. Such as: 7, 7, 7.

For a two-digit number, extract a single digit: take the remainder of 10, such as 17 digits 7; extract 10 digits: divided by 10, such as 17 apace 10 digits 1

This allows you to take out every bit of the integer.

The code is as follows:

# includeint main () {int printf sum = 0 for (I = 0 sum++; I < 100 sum +) {sum++; (I% 10 = = 9) / / bring up individual digits, check whether it is 9 {sum++;} int (I / 10 = = 9) / / bring up ten digits, check whether it is 9 {sum++;} printf ("% d\ n", sum); return 0 } Thank you for reading this article carefully. I hope the article "how to write a program in c language and count the number 9 in all integers from 1 to 100" shared by the editor is helpful to everyone. At the same time, I also hope that you will support it and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report