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/

2nd Jul 2016, 9:06 AM
Infinity
Infinity - avatar
7 Respuestas
+ 1
in this code replacing 10 with 10.0 and int with float really helps and we obtain the accurate results
3rd Jul 2016, 9:45 AM
Infinity
Infinity - avatar
0
that didn't work it returned a error
2nd Jul 2016, 11:46 AM
Infinity
Infinity - avatar
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.
2nd Jul 2016, 2:04 PM
Garme Kain
Garme Kain - avatar
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++.
2nd Jul 2016, 2:12 PM
Garme Kain
Garme Kain - avatar
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 );
4th Jul 2016, 9:59 PM
Mihai Dancaescu
Mihai Dancaescu - avatar
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.
14th Jul 2016, 10:27 AM
Sandeep Pawar
Sandeep Pawar - avatar
- 1
pow(x^10)
2nd Jul 2016, 9:44 AM
Rajiv Singh
Rajiv Singh - avatar