Read two floating-point numbers and prints the value of their difference divided by their product. - C Data Type

C examples for Data Type:float

Introduction

Have the program loop through pairs of input values until the user enters nonnumeric input.

Demo Code

#include <stdio.h>  
int main( void )  
{  //from  www . jav a  2  s  .c o m
    double n, m;  
    double res;  
      
    printf("Enter a pair of numbers: ");  
      
    while (scanf("%lf %lf", &n, &m) == 2)  
    {  
        res = (n - m) / (n * m);  
        printf("(%.3g - %.3g)/(%.3g*%.3g) = %.5g\n", n, m, n, m, res);  
        printf("Enter next pair (non-numeric to quit): ");  
    }  
    return 0;  
}

Result


Related Tutorials