0
How to use square function in C ?
Guys the code goes as #include <stdio.h> #include <math.h> ...... and when I use the sqrt(num) It gives me 2147483635 every time though I used various numbers so can someone tell me whatâs the problem??
4 Answers
+ 1
Try to run this code and see if it works as expected. I was speculating that you *probably* used an inappropriate format specifier when printing the result from `sqrt()` function.
#include <stdio.h>
#include <math.h>
int main()
{
for(int num = 1; num < 101; num++)
{
// sqrt() gives back a `double`
// please mind format specifier -> %lf
printf("sqrt(%d) = %lf\n", num, sqrt(num));
}
return 0;
}
+ 1
There's missing information here, can you tell the type and value of <num> variable? might be the cause.
I think it may help if you can save the code in SoloLearn and share the link instead. Follow this guide to sharing links if you didn't know.
https://www.sololearn.com/post/75089/?ref=app
+ 1
it worked !!
thank you so much
0
itâs an integer (numbers from 1 to 100), i also checked outside the for loop, and printed sqrt(10) to make sure that the problem wasnât with my code, and it gave me 2147.... (that number) instead of 100