浙大版《C语言程序设计(第3版)》题目集 习题10-1 判断满足条件的三位数 (15分)
程序员文章站
2022-06-07 11:46:04
...
#include <stdio.h>
#include <math.h>
int search(int n);
int main()
{
int number;
scanf("%d", &number);
printf("count=%d\n", search(number));
return 0;
}
int search(int n)
{
int i, count, j, digit[3], temp, k;
count = 0;
for (i = 101; i <= n; i++)
{
temp = i;
for (j = 10; j < 32; j++)
{
if (pow(j, 2) == temp)
{
k = 0;
while (temp)
{
digit[k] = temp % 10;
temp /= 10;
k++;
}
if (digit[0] == digit[1] || digit[0] == digit[2] || digit[1] == digit[2])
{
count++;
}
}
}
}
return count;
}
上一篇: php实战第五天
下一篇: 拉格朗日插值法求解函数值