Finding the square root and guessing the number

S

sathyashrayan

(This is not a home work question)

Dear group,
I want a program to find one number between a set of
natural number.A program to guess a number in between a
Natural number set.This should be a simple task but my
mind suddenly got stuck.

I am trying to implement a square root function
as a practice. I am able to code for the perfect square
root number (ex 9 == 3 * 3) .

But for finding the number which not perfect square
I need to find any number between possible multiple of
the given number. I am not very much talented math's
guy, but I even forgot my school math's.So some of my
math's terms are wrong.Don't give out any program but
simply tell me the algo for guessing a number.
 
N

Nick Keighley

sathyashrayan said:
(This is not a home work question)

really? So what real world problem are you trying to solve?
This isn't really a C programming question, it's an algorithm
question so comp.programming would probably be better.
I find your question unclear so you might consider clarifying a
few points.
I want a program to find one number between a set of
natural number.

how can a number be "between" a set of numbers?
Do you mean select a number from a set? Or find
a number between a *pair* of numbers?
A program to guess a number in between a
Natural number set.This should be a simple task but my
mind suddenly got stuck.

I am trying to implement a square root function
as a practice. I am able to code for the perfect square
root number (ex 9 == 3 * 3) .

But for finding the number which not perfect square
I need to find any number between possible multiple of
the given number.

what? I assume english isn't your first language, and as a confirmed
monoglot I admire anyone who posts to a technical newsgroup in their
non-mother tongue. Even so I really don't understand what you are
saying. You need to guess a number between multiples of the given
number?
I am not very much talented math's
guy, but I even forgot my school math's.So some of my
math's terms are wrong.Don't give out any program but
simply tell me the algo for guessing a number.

we'd need to understand the constraints.

for a square root try n/2?
 
A

AG

You will have to solve the problem through iteration. Given a user
input named "number", you want to find the square root of that number.
If "number" is a positive integer, and greater than 1, then
sqrt(number) will be less than 0.5*number. So, as a starting point,
you know that sqrt(number)>0.5*number.

Also you have to decide how much accuracy you want. The more accuracy,
the more iterations. For this example, we will use an accuracy of
0.01.

The following code snippet will start with an initial "guess" of
0.5*number. It will square this amount, and then compare it to number.
If the difference between number and guess is greater than 0.01, then
the program will make guess a little larger. This will continue until
the program has determined that you are within the given accuracy.


variable are number, guess, tol
while(tol>=0.011)
{
tol=abs(number-(guess*guess)); // check accuracy
guess=guess+0.001; // increase guess by 0.001;
}
 
B

bondowine

sathyashrayan said:
(This is not a home work question)

Dear group,
I want a program to find one number between a set of
natural number.A program to guess a number in between a
Natural number set.This should be a simple task but my
mind suddenly got stuck.

I am trying to implement a square root function
as a practice. I am able to code for the perfect square
root number (ex 9 == 3 * 3) .

But for finding the number which not perfect square
I need to find any number between possible multiple of
the given number. I am not very much talented math's
guy, but I even forgot my school math's.So some of my
math's terms are wrong.Don't give out any program but
simply tell me the algo for guessing a number.

I would suggest you google for "Newton's method" or if you are too lazy
to do that then
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.7
 
M

Mark McIntyre

(This is not a home work question)
I am trying to implement a square root function
as a practice. I am able to code for the perfect square
root number (ex 9 == 3 * 3) .

This is offtopic for CLC, which deals with the C Programming Language.
You should ask in comp.programming, where they may have ideas for an
algorithm, and then post back here if you have trouble writing your C
code implementation.
Mark McIntyre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top