By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,663 Members | 762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,663 IT Pros & Developers. It's quick & easy.

Finding the square root and guessing the number

P: n/a
(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.


Apr 22 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
sathyashrayan wrote:
(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?
--
Nick Keighley

"The Nu Tantras Of The Uttarakaulas"
www.nick-keighley.co.uk/john_powers

Apr 22 '06 #2

P: n/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;
}

Apr 22 '06 #3

P: n/a
sathyashrayan wrote:
(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-te...ml#%_sec_1.1.7

Apr 22 '06 #4

P: n/a
On Sat, 22 Apr 2006 21:06:05 +0530, in comp.lang.c , "sathyashrayan"
<sa***********@REMOVETHISgmail.com> wrote:
(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
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.