守形数

 题目截图:

 

思路:

  首先,只有尾数为 0,1,5,6 的数才可能为守形数,所以其他可以直接排除。然后对其他的数进行判断即可。

 

代码如下:

 1 /*
 2     守形数
 3 */
 4 
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <math.h>
 8 #include <stdlib.h>
 9 #include <time.h>
10 #include <stdbool.h>
11 
12 int main() {
13     int N;
14     while(scanf("%d", &N) != EOF) {
15         int g = N%10;                        // 提取尾数 
16         // 只有尾数为 0,1,5,6 的数才可能为守形数
17         if(g==1 || g==5 || g==6 || g==0) {
18             int t = N*N;            
19             int ans=10;                        // 用来提取低位部分 
20             if(N > 10) {
21                 ans = 100;
22             } 
23             if(t%ans == N) {                // 判断是否是守形数 
24                 printf("Yes!\n");
25             } else {
26                 printf("No!\n");
27             }
28         } else {
29             printf("No!\n");
30         }
31     } 
32 
33     return 0;
34 }

 

转载于:https://www.cnblogs.com/coderJiebao/p/HustTest14.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值