...绝对值和实数绝对值。要求从键盘上输入求绝对值的数。C++程序设计...
发布网友
发布时间:2024-05-04 12:25
我来回答
共2个回答
热心网友
时间:2024-08-02 05:25
#include<iostream>
using namespace std;
int abs_1(int);
double abs_1(double);
int main()
{
int a;
double b;
cout<<"Please enter the number of int:";
cin>>a;
cout<<"Pleade enter the number of double:";
cin>>b;
cout<<abs_1(a)<<endl<<abs_1(b)<<endl;
}
int abs_1(int x)
{
if(x>=0) return x;
else return (-1)*x;
}
double abs_1(double x)
{
if(x>=0) return x;
else return (-1)*x;
}
望及时采纳,楼下的不要复制哦
热心网友
时间:2024-08-02 05:24
#include <iostream>
using namespace std;
float ab_s(float x)
{
return x<0?-x:x;
}
int main()
{
float x;
float n;
cout<<"请输入一个实数:"<<endl;
cin>>x;
n=ab_s(x);
cout<<"x的绝对值是"<<n<<endl;
return 0;
}