1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 14:36:19 +00:00
202401-programming-assignments/【实践课外】10.函数1/6-1 符号函数.md

39 lines
601 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
```