2014-11-03 61 views
-3

代碼我是新手程序員,同時運行下面的代碼,我遇到了一個錯誤:錯誤運行以下用C

#include<stdio.h> 
#include<math.h> 
int main() 
{ 
    int num=8,a=pow(10,num); 
    printf("\n%d",a); 
} 

當我運行這段代碼,爲num甚至價值觀,我得到它通過不同的值1.我用GNU GCC編譯器在CODE::BLOCKS中運行了這個。 以下是我的輸出屏幕抓取。

輸出屏幕: enter image description here

+1

數值精度:上給予.... – 2014-11-03 04:20:43

+0

你爲什麼要分配戰俘的返回值保持主題() ,這是一個雙精度,以int?你爲什麼要向我們顯示num = 8的代碼,這顯然不是你運行屏幕轉儲的代碼? – GreenAsJade 2014-11-03 04:29:56

回答

0

請參考以下鏈接: http://linux.die.net/man/3/pow

#include<stdio.h> 
#include<math.h> 
int main() 
{ 
    int num=8; 
    double a=pow(10,num);/* return type of pow() is double not int */ 
    printf("\n%f",a); 
} 
+0

非常感謝 – Scriptonist 2014-11-04 03:10:57