牛筋鹏 2022-03-07 17:15 采纳率: 100%
浏览 66
已结题

pta中6-7完全平方数,有点不能理解为什么执行不出结果。求指导

#include <stdio.h>
#include <math.h>
int IsTheNumber ( const int N );
int main()
{
int n1, n2, i, cnt;
scanf("%d %d", &n1, &n2);
cnt = 0;
for ( i=n1; i<=n2; i++ ) {
if ( IsTheNumber(i) )
cnt++;
}
printf("cnt = %d\n", cnt);
return 0;
}
int IsTheNumber ( const int N )
{
int kpf,a,b,c,d;
if(sqrt(N)==(int)sqrt(N));
{
a=N/100;
b=N%10;
c=N/10;
d=c%10;
if(a==b||a==d||b==d)
{
return 1;
}
}
return 0;
}

  • 写回答

3条回答 默认 最新

  • 关注

    a=N/100;
    b=N%10;
    c=N/10;
    d=c%10;
    这里判断重复数字的方法不对,输入的N并不一定是3位数字,代码修改如下:

    #include <stdio.h>
    #include <math.h>
    int IsTheNumber ( const int N );
    int main()
    {
        int n1, n2, i, cnt;
        scanf("%d %d", &n1, &n2);
        cnt = 0;
        for ( i=n1; i<=n2; i++ ) {
            if ( IsTheNumber(i) )
                cnt++;
        }
        printf("cnt = %d\n", cnt);
        return 0;
    }
    int IsTheNumber ( const int N )
    {
        int a[10],t,i,j;
        if(sqrt((double)N)==(int)sqrt((double)N));
        {
            i=0;
            t = N;
            while(t)
            {
                a[i] = t%10;
                t/=10;
                //判断有无重复数字
                for(j=0;j<i;j++)
                {
                    if(a[j]==a[i])
                        return 1;
                }
                i++;
            }
        }
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月15日
  • 已采纳回答 3月7日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上