2007/11/30

[C++] Finding Square Root without using sqrt()

不用 sqrt 函式自己寫開根號的 code

http://www.dreamincode.net/code/snippet244.htm

[cpp]
/* Code written by Sanchit Karve
A.K.A born2c0de
Contact Me at born2c0de AT hotmail.com

20 August, 2005

*/




#include
#include

using namespace std;


float sqroot(float m)
{
float i=0;
float x1,x2;
while( (i*i) <= m )
i+=0.1;
x1=i;
for(int j=0;j<10;j++)
{
x2=m;
x2/=x1;
x2+=x1;
x2/=2;
x1=x2;
}
return x2;
}

int main()
{
cout << "Enter a Number:";
int no;
cin >> no;
cout << "Square Root using sqroot()= " << sqroot(no) < << "Square Root using sqrt() = " << sqrt(no);

return 0;
}

[/cpp]

2007/11/23

Visual Studio 2005 更換 Project 位置後問題

移動 VS 2005 Project 檔案位置後

無法正常執行可能原因是因為檔案位置改變

導致中斷點失敗

說明在這裡 http://msdn2.microsoft.com/zh-tw/library/h6aesyw2(VS.80).aspx

可能解決方法有三種

1.
工具 -> 選項 -> 偵錯 -> 一般 -> 取消[原始程式檔必須完全符合原始版本]

2.
偵錯 -> 刪除所有中斷點

3.
在中斷點上按右鍵選位置

或是

打開中斷點視窗(偵錯 -> 視窗 -> 中斷點),同樣在中斷點按右鍵選位置

一個一個修改[檔案]位置

或

選取[允許原始程式碼與原始版本不同]

2007/11/22