2 Star 6 Fork 3

Cyouagain / C语言经典编程详解

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
【C语言经典编程】习题5-1 符号函数 (10分).md 1.12 KB
Copy Edit Raw Blame History

微信搜索公众号【IT学长】:

习题5-1 符号函数

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

函数接口定义:

int sign( int x );

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

裁判测试程序样例:

#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 )
{
  if(x>0) return 1;
  else if(x==0) return 0;
  else return -1;
}
C
1
https://gitee.com/cyouagain/C_pta.git
git@gitee.com:cyouagain/C_pta.git
cyouagain
C_pta
C语言经典编程详解
master

Search