473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Finding the square root and guessing the number

(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
4 8419
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cplusplus | last post by:
Hello, I have newbie question. I'm stuck on this current assignment. Write a program that prompts the user for two integer values, passes the values to a function where they are multiplied...
2
by: Protoman | last post by:
Can you help me? For 4, my square root funct gives 4 instead of 2; here's the code: #include <iostream> #include <cstdlib> using namespace std; template<class T> T Abs(T Nbr) {
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
32
by: priyam.trivedi | last post by:
Hi! Could anyone tell me how to find the square root of a number without using the sqrt function. I did it by using Newton's Formula. How can it be done by using the Binomial Theorem/Taylor...
2
by: ryso | last post by:
Hi. i need a code(witten in C) for extracting the square root from a large number(100+ digits). Please help :D.Thanks
10
by: socondc22 | last post by:
my program is trying to use the babylonian algorithm in order to find the square root... i have a number for the number to have the square root taken of and also a number to run the loop... Whenever...
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.