i want code for finding square root using mental arithmetic

Pages: 12
i want code for finding square root using mental arithmetic
Great!
please anyone can tell me this code i don't know how to calculate the square root using mental calculation
can you tell me what is the code for this?
Your question doesn't make sense. "Mental Arithmetic" means specifically that only the human brain is used. Therefore there can be no code. Even if it did, we don't provide fully coded answers to problems that sound like homework on this site.

Try to re-phrase your question and show us what effort you have put into solving it and you will get some help.
my task is to find the square roots using mental arithmetic. can you tell me what i have to do. i don't know how to put the mental arithmetic in a c++ program
there is no more discription for me
We're not going to simply do your homework for you. First, you must discover a way to calculate a square root. When you've got that, come back and we'll help you write code to do those steps.

If you don't care how you do it, the <cmath> library includes sqrt()
This is pretty sad. If you don't understand how to calculate the square root of something then you shouldn't be trying to learn programming.
ok that is it i know man here it is


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "Please enter a number: ";
double a;
cin >> a;
const double EPSILON = 1E-14;
double xnew = a;
double xold;
do
{
xold = xnew;
xnew = (xold + a / xold) / 2;
}
while (fabs(xnew - xold) > EPSILON);

cout << "The square root is " << xnew << "\n";
system("pause");
return 0;
}

and another one


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "Please enter a number: ";
double a;
cin >> a;
double answer = sqrt(a);
cout << answer << "\n";
system ("pause");
return 0;
}
but i'm confused about finding square root by mental arithmetic
give me some hints please i'm beginner
If you already have code, why are you asking for code?
Here is a way to approximate the square root:
Find the square root of x:

Start with a guess G
if G^2 is close to x, stop, return G
else get a new G by taking the quotient of (G+x/G)/2
Repeat

One of your code snippets makes an attempt at it, but you need to tweak the algo for an exact match.
i didn't understand what are you saying
Take the number you want to know the square root of. Call this number x.

Guess a number that is smaller than x. Call your guess G.

Now square G, to find "G squared".

If "G squared" is equal to x, G is the square root of x. Stop.

If "G squared" is not equal to x, get a "new G" like so: New guess = (G + x/G) / 2

Take your new guess, go back three steps, carry on from there.
You can also use continued fractions.
thanks but is this idea fulfil my task?
How about Taylor Polynomials?
Last edited on
is this code is ok aur not for mental arithmetic

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "Please enter a number: ";
double a;
cin >> a;
double answer = sqrt(a);

cout << "Please enter a number to guess that the square root of the previous number is equal to your guess: ";
double g;
cin >> g;
cout <<"The square root of the first entered number is :" << answer << "\n";
if(a = g*g) cout <<"The square root of your guessed number is approximately equal to the square root of the pervious number"<< "\n"<< "\n";
else cout << "The square root of your guessed number is not equal to the square root of the previous number";
cout << "\n";
system ("pause");
return 0;
}
"Mental arithmetic" is not some technical coding term. It means "inside your own head". How do you find a square root inside your own head, without calculator or writing anything down? That ios mental arithmetic.
Pages: 12