Regarding Assignment
Title
Question
Why is the following code wrong? Why can't the main function return float data type? What to do if we have to find the difference between two floating numbers?
Please explain.
<span style="background-color: rgb(250, 250, 250);">
</span>
</span>
<span style="background-color: rgb(250, 250, 250);">#include <stdio.h></span>
<span style="background-color: rgb(250, 250, 250);">
</span>
</span>
void difference(float a, float b)
{
float c = a-b;
printf("The difference between x and y is %f\n", c);
}
float main()
{
float x,y;
printf("Enter the number 1:");
scanf("%f", &x);
printf("Enter the number 2:");
scanf("%f", &y);
difference(x,y);
return 0;
}
C-and-Cpp Scope-Of-Variables 08-09 min 40-50 sec
Answers:
I believe this program is working fine. I executed this program on my end with the inputs given below:
Enter number 1: 3.56
Enter number 2: 1.782
The difference between x and y is 1.778000
In case you are referring to some other point, please let us know.
Login to add comment