John95 John95 - 1 month ago 7
C Question

probl in using functions in c

I want to display an integer output(function1) and a float output(function2),

function1: input an integer number, if the number is odd display odd, else display even

function2: input two float numbers, multiply them by 4 and add them and display the answer.

Whats wrong with this?

#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;
}

Answer

Shoud be

 int function1(int a)
 float function2(float b, float c)

also

 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(p,q));
 printf(" : %d\n",function1(r));
 return 0;
 }