-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsqrt.cpp
More file actions
37 lines (30 loc) · 684 Bytes
/
sqrt.cpp
File metadata and controls
37 lines (30 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
extern "C"
{
double nr_sqrt(double n, double x0, int iterations, bool printIts);
};
int main(int argc, char *argv[])
{
double input;
double x0 = 10;
int iterations = 10;
bool printIts = true;
double result = -1.0;
if (argc != 2)
{
printf("invalid arguments. usage: sqrt 10\n");
return 1;
}
else
{
input = atoi(argv[1]);
}
// get the square root from newton raphson method
result = nr_sqrt(input, x0, iterations, printIts);
// print results
printf("The square root of %f is %f\n", input, result);
return 0;
}