How to create a function that divides two numbers into C?
How to create a function that divides two numbers into C?
int f_divisao (float num1, float num2) / ** function creation ** / { float result; result = num1 / num2;
printf("VALOR DA DIVISÃO DE %f / %f EH: %.2f\n",num1,num2,resultado); /** saida de dados **/
return(f_divisao);
}
int main () {
float num1,num2;
printf("DIGITE OS DOIS VALORES:\n");
scanf("%f%f",&num1,&num2); /** entrada de dados **/
f_divisao(num1,num2); /** retorna os valores para a função f_divisao **/
} // See this one I did!
More briefly this is how:
float dividir(float a, float b)
{
float c=a/b;
return c;
}
This way I put float function in case it will return a float to main. Oh, it's just you do the assignment ... type float d=dividir(a,b)
I hope I have helped you!
int a = 5, b = 2;
float c = 0.0;
c = (float)a/b;
printf("%.1f", c);
return 0;
%.1f
returns with one decimal place%.2f
with two houses and etccc