统计1~n有多少个9 ,n通过参数传入
2016-10-28 23:22
155 查看
//通过编程实现,统计1~n有多少个9 ,n通过参数传入
#include <stdio.h>
int num(int a);
int main()
{
int n; //n为输入的整数变量
printf("Please input a num:\n");
scanf("%d",&n);
num(n);//调用num函数
return 0;
}
int num(int a)
{
int i;
int count = 0;//count用来统计有多少个9,
int b = 0;
int c = 0;
for(i = 1;i <= a;i++)
{
c = i;
while(c)
{
b = c % 10;//取个位
c = c / 10;//去掉一位,继续判断
if(b == 9)
{
count++;//count用来计数
}
}
}
printf("9的个数为:%d\n",count);
return 0;
}
#include <stdio.h>
int num(int a);
int main()
{
int n; //n为输入的整数变量
printf("Please input a num:\n");
scanf("%d",&n);
num(n);//调用num函数
return 0;
}
int num(int a)
{
int i;
int count = 0;//count用来统计有多少个9,
int b = 0;
int c = 0;
for(i = 1;i <= a;i++)
{
c = i;
while(c)
{
b = c % 10;//取个位
c = c / 10;//去掉一位,继续判断
if(b == 9)
{
count++;//count用来计数
}
}
}
printf("9的个数为:%d\n",count);
return 0;
}
相关文章推荐
- 通过编程实现,统计1~n有多少个9 提示:n通过参数传入
- 1.题目:通过编程实现,统计1~n有多少个9 提示:n通过参数传入
- 强化练习1:通过编程实现,分别统计0~n有多少个0~9 提示:n通过参数传入
- .通过编程实现,统计1~n有多少个9 (n通过参数传入)
- 1. 题目:通过编程实现,统计1~n有多少个9 提示:n通过参数传入
- 初入C语言!整数算法练习1:通过编程实现,统计1~n有多少个9 ? 提示:n通过参数传入!
- 通过编程实现,统计1~n有多少个9
- Oracle通过struct传入varchar2参数为null的解决办法
- 处理Main方法中传入的参数--通过阅读Jmeter的源码分析得到
- 如何通过超链接打开Activity并传入参数
- 题目:通过编程实现,统计 1~n 有多少个 9
- wpf 如何将参数通过CommandParameter 传入viewmodel
- winform .exe程序打包修改注册表使其可通过网页触发启动并传入参数
- C#中通过引用来传递参数?有几种?区别?例?(传入参数A,并返回操作后的A)?
- 通过双击ALV中的字段名判断调用的事物代码和传入的参数
- C#中通过Lambda表达式为委托传入更多的参数
- 如何通过shell脚本统计apache使用多少内存
- oracle中通过传入的参数调用表中存存放的存储过程名
- Java 函数的参数引用,通过传入参数带回函数运行结果
- JAVA 通过 JNA 调用 C程序 dll 函数传入中文参数问题