mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-27 08:26:20 +00:00
39 lines
601 B
Markdown
39 lines
601 B
Markdown
|
# 6-1 符号函数
|
|||
|
|
|||
|
本题要求实现符号函数sign(x)。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
int sign( int x );
|
|||
|
```
|
|||
|
其中`x`是用户传入的整型参数。符号函数的定义为:若`x`大于0,`sign(x)` = $$1$$;若`x`等于0,`sign(x)` = $$0$$;否则,`sign(x)` = $$-1$$。
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include <stdio.h>
|
|||
|
|
|||
|
int sign( int x );
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
int x;
|
|||
|
|
|||
|
scanf("%d", &x);
|
|||
|
printf("sign(%d) = %d\n", x, sign(x));
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* 你的代码将被嵌在这里 */
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例:
|
|||
|
```in
|
|||
|
10
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例:
|
|||
|
```out
|
|||
|
sign(10) = 1
|
|||
|
```
|