- 1

i want the root value of these numbers

#include<stdio.h> #include<math.h> int main() { double a; double b; double c; printf("Enter the value for square root\n"); scanf("%lf", a); printf("%lf\n", &a); scanf("%lf", &b); printf("%lf\n", b); c = sqrt(a*a, b*b); printf("The square root is %lf", c); return 0; }

21st Mar 2022, 11:40 AM
Sam Prince
Sam Prince - avatar
3 ответов
- 1
c=math sqrt (a*a)
10th Jun 2022, 4:53 AM
Sharon Christina
Sharon Christina - avatar
+ 6
You're using address operator(&) in printf() instead of scanf() for variable a. sqrt function takes a single argument only. c = sqrt(a*a) or c = sqrt(b*b) Btw, square root of x*x is always x.
21st Mar 2022, 11:51 AM
Simba
Simba - avatar
0
It looks like you want to find the hypotenuse of a triangle. There is a math function for that called hypot(). Your pointers are mishandled in scanf and printf. Here is the corrected code: #include<stdio.h> #include<math.h> int main() { double a; double b; double c; printf("Enter the short sides of the right triangle\n"); scanf("%lf", &a); //<-- added ref printf("%lf\n", a); //<--removed ref scanf("%lf", &b); printf("%lf\n", b); c = hypot(a, b); //was sqrt(a*a, b*b); printf("The hypotenuse is %lf", c); return 0; }
21st Mar 2022, 3:18 PM
Brian
Brian - avatar