Newton's sqrt in c++
C++
#include<bits/stdc++.h>
#define EPSILON 0.001
using namespace std;
double func(double x) {
return x*x*x - x*x + 2;
}
double derivFunc(double x) {
return 3*x*x - 2*x;
}
void sqrt(double x) {
double h = func(x) / derivFunc(x);
while (abs(h) >= EPSILON) {
h = func(x)/derivFunc(x);
x = x - h;
}
cout << "The value of the root is : " << x;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
double x0;
cin >> x0;
sqrt(x0);
return 0;
}
Also in C++:
- Title
- c++ assert
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- c++ excel blank cells
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- how to find the number of cycles in a graph C++
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- c++ convert const char* to LPCWSTR
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- c++ std::copy to cout
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- c++ loop through array
- Category
- C++
- Title
- initialising 2d vector
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- preorder traversal c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- sorting of array in c++
- Category
- C++
- Title
- c++ lettura file
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- pow c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- set c++
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- fill c++
- Category
- C++
- Title
- c++ functions
- Category
- C++
- Title
- how to concatinate two strings in c++
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- rosrun actionlib_msgs genaction.py
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- bool function in c++
- Category
- C++
- Title
- how to convert n space separated integers in c++
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- Qt asynchronous HTTP request
- Category
- C++
- Title
- c++ clear stream
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- UPARAM(ref)
- Category
- C++
- Title
- c++ ambigous error
- Category
- C++
- Title
- how to modulo 10^9+7
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- Arrays hackerrank solution in c++
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- correct sequence of compilation process in c++
- Category
- C++
- Title
- how to delete an element in vector pair in cpp
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorFloating-point exception (SIGFPE
- Category
- C++
- Title
- array syntax in c++
- Category
- C++
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- fast io c++ geeksforgeeks
- Category
- C++