编写一个判断奇偶数的函数,要求在主函数中输入一个整数,通过被调用函数输出该数是奇数偶数的信息。

来源:百度知道 编辑:UC知道 时间:2024/06/01 11:33:41

我用C语言编一下啊。其他语言类似!
#include<stdio.h>
void sort(int n)
{
if(n%2==0)
printf("the number is double \n");
else
printf("the number is odd\n");
}
int main()
{
int n;
printf("please input a number:\n");
scanf("%d",&n);
sort(n);
return 0;
}

#include<iostream>
using namespace std;
void judge(int);
int main()
{
int m;
cout<<"输入一个整数:"<<endl;
cin>>m
judge(m);
return 0;
}
void judge(int n)
{
if(n%2==0) cout<<n<<"是偶数!"<<endl;
else cout<<n<<"是奇数!"<<endl;
}