当前位置:网站首页>C language simple exercise No.17, about the combination of for and while loops
C language simple exercise No.17, about the combination of for and while loops
2022-06-11 22:54:00 【Sky • Shang】
Topic link :
Contains figures 9 Number of numbers _ Niuke Tiba _ Cattle from (nowcoder.com)
matters needing attention :
1. First look at the requirements of the topic , Yes. Find that these numbers contain 9 How many figures are there in total , Instead of asking you how many there are 9
2. Be careful break Use
Question answer :
#include <stdio.h>
int main ()
{
int i = 0;
int count = 0;
for (i = 1;i < 2020;i++)
{
int m = i;// You can't use it directly here i Value , Because it will change , Make it next
// The cycle of cannot reach i The expected value
while (m) // Here we should think of using while loop
{
if (m % 10 == 9)
{
count++;
break;// there break Must add , Because
}
else
{
;
}
m /= 10;// The function of this expression is to modify m Value , Make it work while loop
// Judgment condition
}
}
printf("%d\n",count);
return 0;
}Some comments about the code :
// here Can't be used directly i Value , Because it will make i The value of is modified directly , Make it next i The cycle of cannot reach i The expected value
while(m) Here we should think of using while loop
break;// there break Must add , Because
m /= 10;// The purpose of this expression is In the revision m Value , Make it work while loop
// Judgment condition
边栏推荐
- 5. Xuecheng project Alipay payment
- Four rounding modes in IEEE754 standard
- Research Report on development trend and competitive strategy of global seabed leakage detection system industry
- Daily question -1317 Converts an integer to the sum of two zero free integers
- [technology sharing] after 16 years, how to successfully implement the dual active traffic architecture of zhubajie.com
- 【Uniapp 原生插件】商米钱箱插件
- Alibaba cloud server MySQL remote connection has been disconnected
- 【Day9 文献泛读】On the (a)symmetry between the perception of time and space in large-scale environments
- Computer forced shutdown Oracle login failed
- Exercise 6-2 using functions to sum a special series of a numbers (20 points)
猜你喜欢

论文阅读《Dense Visual SLAM for RGB-D Cameras》

What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)

Lekao.com: what is the difference between Level 3 health managers and level 2 health managers?

遇到表格,手动翻页太麻烦?我教你写脚本,一页展示所有数据

If I take the college entrance examination again, I will study mathematics well!

Google搜索為什麼不能無限分頁?

Analysis of the implementation principle of an open source markdown to rich text editor

16 | floating point numbers and fixed-point numbers (Part 2): what is the use of a deep understanding of floating-point numbers?

Cloudcompare source code analysis: read ply file
![Tensorflow [actual Google deep learning framework] uses HDF5 to process large data sets with tflearn](/img/d0/586b9f09dc19d5aaf8ccca687b7b10.jpg)
Tensorflow [actual Google deep learning framework] uses HDF5 to process large data sets with tflearn
随机推荐
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
2022新兴市场品牌出海线上峰会即将举办 ADVANCE.AI CEO寿栋将受邀出席
Meetup回顾|DevOps&MLOps如何在企业中解决机器学习困境?
Analysis of the implementation principle of an open source markdown to rich text editor
Determine whether the linked list is palindrome structure
IEEE-754 floating point converter
3.3 naming rules of test modules
【Uniapp 原生插件】商米钱箱插件
leetcode 中的位运算
The second bullet of in-depth dialogue with the container service ack distribution: how to build a hybrid cloud unified network plane with the help of hybridnet
Four rounding modes in IEEE754 standard
Exercise 9-5 address book sorting (20 points)
論文閱讀《Dense Visual SLAM for RGB-D Cameras》
Exercise 6-2 using functions to sum a special series of a numbers (20 points)
Exercise 11-2 find week (15 points)
Mobile terminal - picture timeline of swipe effect
Want to be iron man? It is said that many big men use it to get started
Exercise 9-6 statistics of student scores by grade (20 points)
【Day10 文献泛读】Temporal Cognition Can Affect Spatial Cognition More Than Vice Versa: The Effect of ...
习题6-2 使用函数求特殊a串数列和 (20 分)