2014-09-29 61 views
-5
int x = 1; 

int main() 
{ 
    int N = 20; 
    for (int i=1;i<=N;i++){ 
     float h = pow(10,-i); 
     cout << h << endl; 
     cout << r=(sqrt(x+h)-sqrt(x))/h; 
    } 
    cout << 1/sqrt(2*x) << endl; 
} 

我有一個是應該輸出數的程序,如:爲什麼我的xCode編譯器輸出「lldb」?

0.1, 0.01, 0.001, etc 

但所有它輸出是

lldb 

什麼LLDB是什麼意思?

+0

你去哪兒宣佈'N'? – Shoe 2014-09-29 22:34:57

+2

你好嗎? 'lldb'是一個調試器提示符。 – 2014-09-29 22:35:00

+0

循環中的N是多少? – 2014-09-29 22:35:02

回答

3

我想你可能在Mac上使用Xcode運行這個程序,因爲lldb是這種設置的默認調試器。

如果是這樣的話,只需鍵入'run',看看會發生什麼。如果你是初學者,你可能會有更好的運氣建立一個命令行環境來構建和運行你的程序。

+0

我正在做這一切。請參閱編輯。 – 2014-09-29 22:40:20

+1

@DonLarynx我沒有看到任何編輯。 – 2014-09-29 22:41:26

+0

正如我在使用命令行環境 – 2014-09-29 22:47:28

0

代碼本身是正確的,這可能意味着您可能無法在您的環境中正確運行它。我複製你的函數,它就像一個魅力:

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

using namespace std; 

int main() 
{ 
    int N = 20; 
    for (int i=1;i<=N;i++){ 
     double h = pow(10,-i); 
     cout << h << endl; 
    } 
} 

編譯它使用控制檯

$ g++ file.cpp 
$ ./a.out 

0.1 
0.01 
0.001 
0.0001 
1e-05 
1e-06 
1e-07 
1e-08 
1e-09 
1e-10 
1e-11 
1e-12 
1e-13 
1e-14 
1e-15 
1e-16 
1e-17 
1e-18 
1e-19 
1e-20