C语言初阶习题【9】数9的个数

1.编写程序数一下 1到 100 的所有整数中出现多少个数字9

2.思路

循环遍历1到100,需要判断每一位的个位数是否为9,十位数是否为9,每次符合条件就count++进行计数,最后输出count,即可

3.code

c 复制代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
    int i = 0;
    int count = 0;
    for (i = 1; i <= 100; i++)
    {
        if (i % 10 == 9)
        {
            count++;
        }
        if (i / 10 == 9)
        {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}
相关推荐
AI玫瑰助手8 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车8 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋8 小时前
C++14特性
开发语言·c++·c++14特性
JAVA社区10 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
弥树子10 小时前
踩坑记录:服务器内网调用接口,真实请求URL与官方公开URL不一致问题排查
开发语言·php
z落落10 小时前
C# ToCharArray + foreach遍历 + String与StringBuilder
开发语言·c#
Bluetooth73011 小时前
c语言一维数组
c语言
学代码的真由酱11 小时前
Java多用户一对一网页聊天室-测试报告
java·开发语言·功能测试·测试
人道领域11 小时前
【LeetCode刷题日记】669.修剪二叉搜索树
开发语言·python·算法
xiaoshuaishuai811 小时前
C# AvaloniaUI动态显示图片
开发语言·c#