C语言 sgn 符号函数:定义与调用
sgn符号函数可以定义为:
int sgn(int n) {
if (n > 0) return 1;
else if (n < 0) return -1;
else return 0;
}
调用方式:
int result = sgn(number);
其中,'number'为需要判断符号的整数,'result'为返回的符号值,可能为1、-1或0。
原文地址: https://www.cveoy.top/t/topic/kpLN 著作权归作者所有。请勿转载和采集!