1~100的所有整数中出现9的个数

mac2025-05-16  20

一、描述:

1~100的所有整数中出现9的个数。

二、代码:

#include<stdio.h> #include<windows.h> int main(){ int i = 0; int count=0; for (i = 1; i <= 100; i++){ if (9==i % 10){ //计算个位数中9的个数 count++; } if (9==i / 10){ //计算十位数中9的个数 count++; } } printf("1~100中9出现个数:%d\n", count); system("pause"); return 0; }

三、运行结果

最新回复(0)