c语言sgn符号函数怎么定义 调用方式
sgn符号函数可以定义如下:
int sgn(int x) {
if (x > 0) {
return 1;
} else if (x == 0) {
return 0;
} else {
return -1;
}
}
调用方式为:
int result = sgn(x);
其中,x为需要判断符号的数值,result为返回的符号值,1表示正数,0表示0,-1表示负数。
原文地址: https://www.cveoy.top/t/topic/c2bV 著作权归作者所有。请勿转载和采集!