#include<stdio.h>
#include<math.h>
int judge( int num )
{
int sum = 0;
while(num != 0)
{
num = num / 10;
sum++;
}
return sum;
}
int count_nine(int input)
{
int count=0;
int amount=0;
int k;
int i = 1 ;
for(i = 1 ;i <= input; i++)
{
int j = i;
while(j >= 9)
{
k = judge(j);
int a;
if(k == 1 )
{
a = 10;
}
else
{
a = pow( 10 , k-1 );
}
int result;
result = j / a ;
if(result == 9 )
{
count++;
}
j = j % a ;
if (j == 9 )
{
count++;
break;
}
}
}
return count;
}
int main()
{
int n;
printf("please input n:");
scanf("%d",&n);
printf("%d nine from 1 to%d",count_nine(n),n);
}
#include <stdio.h>
int wanshu(int n);
int main()
{
int m;//m是输入的数字
printf("请输入一个数:\n");
scanf("%d",&m);
ptintf("这个数的完数是:\n");
wanshu(m);
printf("\n");
return 0;
}
int wanshu(int n)
{
int i,j;//i用来判断1~N的数
int s = 0;//sy用来求和
int t = 0;//t判断是否是因子
for(i = 1;i <= n;i++)
{
for(j = 1;j < i;j++)//j是除了i本身之外的1-i-1的数
{
t = i % j;
if (t == 0)
{
s += j;
}
}
if (s == i)//满足完数条件就输出
{
printf("%d\t",i);
}
s = 0;//每判断一个数,就初始化一次
}
}
1. 题目:通过编程实现,统计1~n有多少个9 提示:n通过参数传入#include&lt;stdio.h&gt;#include&lt;math.h&gt;int judge( int num ){ int sum = 0; while(num != 0) { num = num / 10; sum++; } return s...