您的位置:首页 > 编程语言 > C语言/C++

C语言:编写程序数一下 1到 100 的所有整数中出现多少次数字 9

2016-05-30 17:12 681 查看
#include<stdio.h>
#include<stdlib.h>

void NineNumber()
{
int num = 1;
int count = 0;
int unit = 0;
int ten = 0;
int hundred = 0;

for (; num <= 100; num++)
{
hundred = num / 100;
ten = (num - hundred * 100) / 10;
unit = (num - hundred * 100 - ten * 10) / 1;

if (hundred == 9)
{
count++;
}
if (ten == 9)
{
count++;
}
if (unit == 9)
{
count++;
}
}
printf("%d\n", count);
}

int main()
{
NineNumber();
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐