[2 days left] Whatâ€™s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Math

Posted on 1998-11-01
Medium Priority
218 Views
How do I get the square root of a number?
0
Question by:p314159265
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Accepted Solution

thresher_shark earned 800 total points
ID: 1253987
0

LVL 6

Expert Comment

ID: 1253988
To calculate the square root of a number, use the sqrt function like so:

#include <math.h>
.
double number = 4.0;
double result = sqrt (number);
ASSERT (result == 2.0);
0

LVL 6

Expert Comment

ID: 1253989
0

Author Comment

ID: 1253990
What does 'ASSERT' do?
0

LVL 6

Expert Comment

ID: 1253991
"ASSERT" performs a test that, if failed, will stop the program's execution.  In this case, it is basically saying, "If the square root of 4 is not 2, then stop the program from running."  Obviously, you would want that to happen because the square root of 4 is obviously 2.

0

Author Comment

ID: 1253992
0

LVL 5

Expert Comment

ID: 1253993
Of course, you don't NEED to use ASSERT...  Thresher just put it there as a code snippet to prove that the sqrt function works.

a=sqrt(b) is the only code you really need.
0

LVL 6

Expert Comment

ID: 1253994
Yes, thank you scrapdog for clarifying :-)
0

LVL 1

Expert Comment

ID: 1253995
I think you can use this function to get n root of a
Give a = x^n
=> x = exp((1/n)*log(a))
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and infâ€¦
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
###### Suggested Courses
Course of the Month14 days, 17 hours left to enroll