PRODUCT OF TWO NUMBERS USING FUNCTION - RETURNS A FLOAT
Do you like this story?
This program seems to be rather simple. But there's one little thing to be noted in this particular program. The thing is that the function in this program returns a float. The function declaration is usually given outside main..but due to some other standards that I am following, I have prototyed it inside main..but that doesn't cause much of a difference in this simple program.
Write a function which receives a float and an int from main(), finds the product of these two and returns the product which is printed through main().
#include
main()
{
int i;
float j, prod;
float product (int x, float y);
printf("Enter the i(int) and j(float):");
scanf ("%d %f", &i, &j);
prod = product(i,j);
printf("Product:%f", prod);
}
product (int x, float y)
{
float product;
product = x*y;
return (product);
}
main()
{
int i;
float j, prod;
float product (int x, float y);
printf("Enter the i(int) and j(float):");
scanf ("%d %f", &i, &j);
prod = product(i,j);
printf("Product:%f", prod);
}
product (int x, float y)
{
float product;
product = x*y;
return (product);
}

This post was written by: Rajendra Prasad
Rajendra Prasad is a professional blogger, web designer and front end web developer. Follow him on Facebook