How to use square function in C ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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??

15th Jun 2020, 3:14 AM
Rowan
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; }
15th Jun 2020, 3:32 AM
Ipang
+ 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
15th Jun 2020, 3:21 AM
Ipang
+ 1
it worked !! thank you so much
15th Jun 2020, 3:58 AM
Rowan
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
15th Jun 2020, 3:24 AM
Rowan