#include<iostream>
using namespace std;
int main()
{
float x;
cin>>x;
int sgn;
if(x==0)
sgn=0'
else // 在x不等于0的情况下,再进一步区分想x>0和x<0的这两种情况
{
if(x>0) sgn=1;
else sgn=-1;
}
cout<<sgn<<endl;
return 0;
}
求符号函数sgn(x)的c++程序
最新推荐文章于 2024-03-22 22:07:48 发布