其他分享
首页 > 其他分享> > 6-7 判断自守数 (10 分)

6-7 判断自守数 (10 分)

作者:互联网

所谓自守数(也称守形数),是指其平方数的低位部分恰为该数本身的自然数。例如:252=625, 因此 25 是自守数。

注:0 和 1 也算自守数。

请编写函数,判断自守数。

函数原型

int IsAutomorphic(int x);

说明:参数 x 是自然数。若 x 为自守数,则函数值为 1(真),否则为 0(假)。

裁判程序

#include <stdio.h>

int IsAutomorphic(int x);

int main()
{
    int n;
    scanf("%d", &n);
    if (IsAutomorphic(n))
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

/* 你提交的代码将被嵌在这里 */

输入样例1

25

输出样例1

Yes

输入样例2

37

输出样例2

No
int IsAutomorphic(int x)
{
	int y = x * x;
	while (x)
	{
		if (x % 10 != y % 10)
			return 0;
		x /= 10;
		y /= 10;
	}
	return 1;
}

 

标签:10,判断,return,int,样例,自守数,IsAutomorphic
来源: https://blog.csdn.net/qq_40035365/article/details/122190353