1.devise a function min(x,y)that returns the smaller of two double values,and test the function with a simple driver,
2.write a program that inputs a series of integers (say,3,integers)and passes them one at a time to function even which uses the remainder operator (modulo division operator)to determine if an integer is even .the function should take an integer argument and return 1 if the integer is even and 0 otherwise.
2、写一段能输入多个整数的程序,要求每次传递给函数一个整型参数,用取模运算符去判断它是否是偶数。如果是偶数就返回整型的1,否则返回0.
even应该是偶数的意思。追问
能告诉我怎么编这2个程序嘛 谢谢 有追加
追答if(a%2)
printf("not even number!\n");
else
printf(" even number!\n");
2.write一个程序,输入一系列的整数(说、3、整数)并送一次甚至采用功能分区经营者剩余操作员(模)来确定的正整数,功能甚至应该采取整数参数和返回1如果整数甚至和0了
2.编写一个程序,输入一系列整数(例如3个整数),并将它们分别作为参数传送给一个判断是否是偶数的函数。此此函数用模除法运算来判断一个整数是否是偶数。函数有一个参数,如果该参数是偶数,函数返回1,否则返回0。追问
能帮忙写下这2个程序吗 谢谢
追答//1
#include
double min(double a,double b)
{
return a>b?b:a;
}
void main()
{
printf("min=%f\n",min(1.0,2.0));
}
//2
#include
int even(int a)
{
return a%2==0;
}
void main()
{
int a;
for(int i=0;i<3;i++)
{
scanf("%d",&a);
if(even(a))
printf("even number!\n");
else
printf("not even number!\n");
}
}