2020-11-26

6-2 使用函数判断完全平方数 (10分)

重点:if ( (int)sqrt(n)== sqrt(n) )

 

int IsSquare( int n )
{
    int x;
    if ((int)sqrt(n) == sqrt(n))
        x=1;
        
    else 
        x=0;
        return x;
}

错误点:

int IsSquare( int n );这里没有分号(这里的n表示输入的函数n)
{
    int x 这里表示新定义的函数
    if ((int)sqrt(n) == sqrt(n))----------------判断输入函数是否为完全平方数,完全平方数的表达方式为:sqrt(n).      判断是否定于用符号==
        x=1;      
    else 
        x=0;
        return x(0);    返回初始值x,错误点写成0
}

 

 

纠错点:第一行分号输入中文;

a.c:20:22: error: stray ‘\357’ in program int IsSquare( int n );

^ a.c:20:23: error: stray ‘\274’ in program int IsSquare( int n );

^ a.c:20:24: error: stray ‘\233’ in program int IsSquare( int n );

^ a.c: In function ‘IsSquare’: a.c:26:5: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation] else ^~~~

a.c:28:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘else’ return x; ^~~~~~ a.c: In function ‘main’:

a.c:10:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^~~~~~~~~~~~~~~

第一行输入英文分号:

a.c:21:1: error: expected identifier or ‘(’ before ‘{’ token { ^

a.c: In function ‘main’:

a.c:10:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^~~~~~~~~~~~~

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值