473,320 Members | 1,909 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,320 software developers and data experts.

how to use sqrt in c

whenever i try to use sqrt, i get a reply that says :undefined function to sqrt in main.

so where am i wrong.

Here is my source code

#include<stdio.h>
#include<math.h>
int a,b;
main(void)
{

printf("Enter a number:");
scanf("%d", &a);

b=sqrt(a);

printf("%d", b);

}
Mar 1 '12 #1
3 2176
weaknessforcats
9,208 Expert Mod 8TB
You may not be including the library containing sqrt code.

When I compile i just get a warnng about possible loss of data since sqrt has a double argument and a duble return type. You are converting the return to an int which has no decimals places hence the warning.
Mar 1 '12 #2
Now how should it be
Mar 1 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
Look in your makefile and see if the library for math.h is there. Just including the header file does not include the function. An error of "unresolved function" is almost certainly coming from the linker since you already told the compiler there was an sqrt function by including math.h.
Mar 1 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Prune Tracy | last post by:
Hi, I can't get this seemingly harmless code to compile with Comeau online. #include <cmath> typedef float (*float_func)(float); typedef double (*double_func)(double); int main() {...
10
by: pauldepstein | last post by:
I am writing a program which will use the ceiling and floor of square roots. If a positive integer is an exact square (and is not overly huge), does sqrt return an integer-valued real? Or...
7
by: Aric | last post by:
Hi, I'm a bit new to programming in general, really I've just picked it up as a hobby, and so I've started by reading "Practical C Programming" by Steve Oualline. Things have been going fine in...
1
by: Reiner Apke | last post by:
Hello, I have got a very strange problem with the calcualtion of the the square root (Math.Sqrt()). I calculate in a loop a lot of of diameters maxDiameter = Math.Sqrt(maxCrossSection *...
13
by: Michael McNeil Forbes | last post by:
I would like to write a module that provides some mathematical functions on top of those defined in math, cmath etc. but I would like to make it work with "any" type that overloads the math...
12
by: Thomas Zhu | last post by:
hello all, n is an 32bit-integer, how to calculate sqrt(n) I know high(n) is the the value, but how to use bit operation to implement this function. thanks in advance. yours Yin
14
by: peng.xiaoyu | last post by:
hello everyone, why this c code can be compiled and linked without -lm? #include<math.h> #include<stdio.h> int main() { printf("%f\n",sqrt(2.0)); return 0;
13
by: siggi | last post by:
Hi all, this is a newbie question on : Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32 PC with WinXP In http://www.python.org/doc/2.3.5/lib/module-math.html I read:
30
by: copx | last post by:
I am writing a program which uses sqrt() a lot. A historically very slow function but I read on CPUs with SSE support this is actually fast. Problem: C's sqrt() (unlike C++ sqrt()) is defined to...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.