欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

浙大版《C语言程序设计(第3版)》题目集 习题10-1 判断满足条件的三位数 (15分)

程序员文章站 2022-06-07 11:46:04
...

浙大版《C语言程序设计(第3版)》题目集 习题10-1 判断满足条件的三位数 (15分)

#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;
}