Write a program to count how many times the number 9 occurs in all integers from 1 to 100.

First we define the variable

Use for loop to find numbers within 100

Then judge the various situations where 9 appears

9,19,29,39,49,59,69,79,89,90,91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 ,99

The ones place is 9, or the tens place is 9

code show as below:




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324801569&siteId=291194637