0
Can anyone tell me how to use a variable in the pow function in c language.
when I write #include <stdlib> #include <math.h> int x, y; cin>>x; y=pow(10,x); cout<<y; when I input 2 the output comes out to be 99 open the code to see ur self http://www.sololearn.com/app/cplusplus/playground/cKgG2zgwO0W2/
7 Respuestas
+ 1
in this code replacing 10 with 10.0 and int with float really helps and we obtain the accurate results
0
that didn't work it returned a error
0
It is because the compiler you are using (the SoloLearn one). I've compiled the same code in gcc and the output is the correct one.
0
Edit:
You are using cin without having iostream header nor telling the compiler wich cin or cout to take. You have to tell him that you are using the std namespace within iostream header.
Or you can use the printf, and scanf functions, found in the stdio.h(C) or cstdio(C++) header file, as your question asks for C, not C++.
0
Pow has a bug in it. When you call it the second time, the answer will be wrong. Also, you should use y = ( int ) pow ( 10.0f , ( float ) x );
0
Because of integer truncation. pow()returns a floating point value, and due to floating point arithmetic, it is probably ~99.999...; however, due to integer truncation, even 99.999... gets truncated down to 99.
- 1
pow(x^10)