求大家!用c++语言,写一个函数,功能判断任意数值的奇偶性。

2025-02-23 17:53:25
推荐回答(2个)
回答1:

#include

using namespace std;

int st(int x)//自定义函数 

{

if(x%2==0)

return 1;

return 0;

}

int main()

{

int x;

cin>>x;

if(st(x)==1)//调用函数 

cout<<"偶数";

else

cout<<"奇数";

return 0;

}

回答2:

int f(int a) { return a%2; }