This question requires the realization of the sign function sign(x).
Function interface definition:
int sign( int x );
Where x is an integer parameter passed in by the user. The sign function is defined as: if x is greater than 0, sign(x) = 1; if x is equal to 0, sign(x) = 0; otherwise, sign(x) = −1.
Sample referee test procedure:
#include <stdio.h>
int sign( int x );
int main()
{
int x;
scanf("%d", &x);
printf("sign(%d) = %d\n", x, sign(x));
return 0;
}
/* 你的代码将被嵌在这里 */
Input sample:
10
Sample output:
sign(10) = 1
answer:
int sign( int x )
{
//若x大于0,sign(x) = 1;若x等于0,sign(x) = 0;否则,sign(x) = 1。
if(x>0) return 1;
else if(x==0) return 0;
else return -1;
}