Jump to content

Square Roots

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Olympiaus

Olympiaus

    Newbie

  • Members
  • Pip
  • 7 posts
Is there a function i can use to figure the square root of numbers? i was trying to make a program for solving pythagorean theorem problems for my friend, but i can't find the square root of C haha. If its not possible let me know

btw, im a noob...
Posted Image

#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Code;
#include <math.h>
y = sqrt(x);

Description;
"sqrt" returns the square root of "x". If "x" is negative, "sqrt" returns zero and sets "errno" to EDOM.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Wow great help Brandon. Didn't know that you knew some C++.

Olympiaus, I wanna bring your attention to this math bits page: Math Functins in C++

It lists a bunch of mathematical functions in C++. The one you are interested in is hypot(a,b).

#4
Olympiaus

Olympiaus

    Newbie

  • Members
  • Pip
  • 7 posts
thanks soooooo much

this community replies so fast haha
Posted Image

#5
PythonPower

PythonPower

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 230 posts
More generally, to find the nth root of x, use pow(x, 1.0/n).

#6
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Your welcome mate, if you need any further help just ask and we shall reply as soon as possible ;)
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#7
TrakStar

TrakStar

    Newbie

  • Members
  • Pip
  • 4 posts
Our class wrote actually wrote a program that calculated it:
while (cin)
{
	if (a<=0)

cout << "******Can you please insert a positive integer!*******";
	cout << endl;

	
	break;
}

cout << endl;
do

{ //calculation to find the root
	x=(x+a/x)/2;

	cout << "The Square root of"  << " " << a << " " << "is" << " " << x <<endl;
}
//parameter for when to stop calculation
while (x-a/x>=0.000001);

Edited by WingedPanther, 30 April 2009 - 07:07 AM.
add code tags (the # button)