hypot(), hypotf() & hypotl()
We will get Square root of ( x2 + y2 ) of any two numbers by using hypot()
function.
Example with integer variable
#include <stdio.h>
#include <math.h>
int main(void){
int hypt;
hypt = hypot(3, 4);
printf("%d", hypt);
return 0;
}
Ouptut is here
5
Example with float variable using hypotf()
#include <stdio.h>
#include <math.h>
int main(void){
float hypt;
hypt = hypotf(5, 4);
printf("%f", hypt);
return 0;
}
The above code will give this output.
6.403124
Example with double type variable using hypotl()
#include <stdio.h>
#include <math.h>
int main(void){
double hypt;
hypt = hypotl(7, 9);
printf("%f", hypt);
return 0;
}
Output is here
11.401754
Example : without using hypot and by using sqrt()
sqrt()
#include <stdio.h>
#include <math.h>
int main(void){
double hypt;
hypt = sqrt((7*7)+ (9*9));
printf("%f", hypt);
return 0;
}
Output
11.401754
This article is written by plus2net.com team.
plus2net.com