0

HELP when I run this program (in c language) and input the value 2 the output comes out to be 99. I'm using GNU GCC compiler. Can anyone please explain?

#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int x,y; printf("\n\nenter the value of 10 = "); scanf("%d",&x); y=pow(10,x); printf("\nRESULT OF POWER OF Y = %d\n",y); return 0; }

1st Jul 2016, 9:24 AM
Infinity
Infinity - avatar
2 Answers
+ 1
Re-install your compiler. The code should work.
5th Jul 2016, 8:13 PM
Mihai Dancaescu
Mihai Dancaescu - avatar
- 1
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. ref--google
14th Jul 2016, 10:25 AM
Sandeep Pawar
Sandeep Pawar - avatar