Create a function called min(x,y) that returns the smaller of two double values using conditional operator. - C Function

C examples for Function:Function Definition

Description

Create a function called min(x,y) that returns the smaller of two double values using conditional operator.

Demo Code

#include <stdio.h>  
  
double min(double, double);  

int main(void){  
    double x, y;  
      //from  ww  w  .  j av a2 s  .c o m
    printf("Enter two numbers (q to quit): ");  
    while (scanf("%lf %lf", &x, &y) == 2)  
    {  
        printf("The smaller number is %f.\n", min(x,y));  
        printf("Next two values (q to quit): ");  
    }  
    printf("Bye!\n");  
        
    return 0;  
}  
  
double min(double a, double b)  
{  
    return a < b ? a : b;  
}

Result


Related Tutorials