Reputation: 105
Can I use a return command instead of printf in the tables1 function, and still get the same output as it is giving me currently? The tables1 function is defined at the starting of the following code which presently executes without warnings or errors:-
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
float tables1(float a,float b)
{
int i=0;
for(i=0;i<=10;i++)
{
printf(" %.2f\n", a*i);
printf(" %.2f\n ", b*i);
}
printf(" if all tasks not executed plz check the code \n");
printf("just to check how the computer treated your number input as, lets print it again\n %.2f \n", a);
return 0;
}
int main()
{
float a,b;
printf("enter the numbers whose first 10 multiples u want to see\n");
scanf("%f", &a);
scanf("%f", &b);
printf("following below are the multiples \n\n ");
tables1(a,b);
return 0;
}
The output image is attached.
Also, when i wrote the above code initially, i did not write any return statement in the tables1 function definition, hence i got a warning during build, so just to see if it works, i wrote a return 0; compiled it, and the warning was gone yet, leaving me in dissatisfaction from a second query which is:- Doesnt the float function have a different kind of return statement, or is return 0 rightly used? i feel there may be couple of such instances(like mistakes) in my program that may have gone unnoticed by me.
Upvotes: 0
Views: 679
Reputation: 42149
You aren't using the return value of tables
anywhere. Furthermore, tables
already takes a float
as input, hence you cannot really check inside tables
whether that number matches the user's input, since the input (a string) is unknown to tables
.
You might as well change the function to void tables
and not return any value. The part of the code that deals with the user's input is in main
, and there is no need to pass such details onto a function dealing with float
s.
Meanwhile scanf
does return a value which you are also ignoring – do check the documentation of each library function you are using, and determine whether the return value might be useful... (There are also other functions to parse numbers from strings, e.g., strtod
.)
Upvotes: 1