首页 > 其他 > 详细

习题5-1 符号函数 (10分)

时间:2020-03-28 15:10:42      阅读:581      评论:0      收藏:0      [点我收藏+]

本题要求实现符号函数sign(x)。

函数接口定义:

int sign( int x );
 

其中x是用户传入的整型参数。符号函数的定义为:若x大于0,sign(x) = 1;若x等于0,sign(x) = 0;否则,sign(x) = −。

裁判测试程序样例:

#include <stdio.h>

int sign( int x );

int main()
{
    int x;

    scanf("%d", &x);
    printf("sign(%d) = %d\n", x, sign(x));

    return 0;
}

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

输入样例:

10
 

输出样例:

sign(10) = 1



int sign( int x){
    int y;
    if(x>0)
        y=1;
    else if(x==0){
        y=0;
    }
    else if(x<0){
        y=-1;    
    }
    return y;
}

 

习题5-1 符号函数 (10分)

原文:https://www.cnblogs.com/Kimsohyun/p/12578911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!