我想显示整数输出 (function1
) 和浮点输出 (function2
)。
function1
:输入一个整数,如果是奇数则显示奇数,否则显示偶数。
function2
:输入两个 float ,乘以4相加并显示结果。
这有什么问题吗?
#include<stdio.h>
function1(int a)
{
if(a%2!=0)
{printf("odd number");}
else
{printf("even number");}
return a;
}
function2(float b, float c)
{
float d;
b=b*4;
c=c*4;
d=b+c;
return d;
}
main()
{
float p,q;
int r;
printf("Input 2 float numbers\n");
scanf("%f %f",&p,&q);
printf("Input a integer number\n");
scanf("%d",&r);
printf("%f\n",function2());
printf(" : %d\n",function1());
return 0;
}
最佳答案
c 中的函数需要返回类型:
return_type function_name( parameter list ) {
body of the function
}
如果要输出 int,请执行以下操作:
int function( int a ) {
return a;
}
参见:https://www.tutorialspoint.com/cprogramming/c_functions.htm
获取更多帮助
关于c - c中函数使用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40136762/