C examples for Operator:Arithmetic Operator
Calculate harmonic mean of two numbers which is taking the inverses of the two numbers, averaging them, and taking the inverse of the result.
#include <stdio.h> double harmonic_mean(double, double); int main(void) { double x, y;/* ww w .j a v a 2 s. c om*/ printf("Enter two numbers: "); while (scanf("%lf %lf", &x, &y) == 2){ printf("%f\n", harmonic_mean(x, y)); printf("Enter two numbers: "); } return 0; } double harmonic_mean(double x, double y) { return 2 / (1 / x + 1 / y); }