Efficient Programming: Troubleshooting Pow Function

  • Thread starter Thread starter beanryu
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 4K views
beanryu
Messages
90
Reaction score
0
I wrote the following "program"

#include <stdio.h>
#include <math.h>


int main()
{
double x,y;

printf("enter a number");
scanf("%FL,&x_one");


y = pow(x,3.0) - 4.0*x + 1.0;
printf("%d",y);

return 0;

}

could anyone tell me why I can't get a correct result from this?
What had I done wrong with the pow(power) operation?
THANX!
 
Physics news on Phys.org
The line

scanf("%FL,&x_one");

doesn't make any sense. Did you put the quote marks in the wrong place? Did you mean:

scanf("%FL", &x_one);

Of course, the variable x_one doesn't exist in your program, and you probably should use lowercase characters in your scanf -- like "%fl".

- Warren
 
even I corrected the errors you pointed out to me...

i can't get any other result but the degit "0"!
I use miracle C to compile it.

corrected program:
#include <stdio.h>
#include <math.h>


int main()
{
double x,y;

printf("enter a number");
scanf("%fl",&x);


y = pow(x,3.0) - 4.0*x + 1.0;
printf("%d",y);

return 0;

}

I think the "pow" function is not being recognized...
whatever vulue I enter in the parathesis after pow function, it returns 1!
 
Last edited:
Is %fl allowed in C at all? I know %f is.
 
my textbook said yes, its a must in a scanf() thing

the thing is the program works fine when its

y = x*3.0) - 4.0*x + 1.0
or y = x-3.0 - 4.0*x + 1.0
or whatever other thing I tried

just not pow(x,3.0)
 
If you change your scanf and your printf statements to this
Code:
...
scanf("%lf",&x);
...
printf("%lf", y); 
...
it should work (I tried it, and it works fine)