silveira13
08-22-2008, 07:12 AM
Please, I need to calculate the square root of integers. Do someone know how to do this?
davekw7x
08-22-2008, 09:37 AM
I need to calculate the square root of integers...
//
// test_sqrt.cpp
//
#include "../code/nr3.h"
int main()
{
int i;
char c;
cout << "Enter an integer: ";
while (cin >> i) {
cout << "The square root of "
<< i << " is equal to "
<< sqrt(Doub(i)) << endl;
cout << endl << "Enter an integer: ";
}
cout << endl;
return 0;
}
Output:
$ g++ -Wall -W test_sqrt.cpp -o test_sqrt
$ ./test_sqrt
Enter an integer: 1
The square root of 1 is equal to 1
Enter an integer: 2
The square root of 2 is equal to 1.41421
Enter an integer: 3
The square root of 3 is equal to 1.73205
Enter an integer: 10
The square root of 10 is equal to 3.16228
Enter an integer: 100
The square root of 100 is equal to 10
Enter an integer: 1000
The square root of 1000 is equal to 31.6228
Enter an integer: 10000
The square root of 10000 is equal to 100
Enter an integer: 100000
The square root of 100000 is equal to 316.228
Enter an integer: 99
The square root of 99 is equal to 9.94987
Enter an integer: quit
$
Now: What is your question (assignment)? Really?
Regards,
Dave