求三个数的最大值和最小值(C程序)

来源:互联网 发布:newman 复杂网络 编辑:程序博客网 时间:2024/05/16 08:14
//////////////////////////////////////////////////////
//求三个数的最大值和最小值 
///////////////////////////////////////////////////// 
#include <stdio.h> 
#include <stdlib.h>


float compTwo(float x, float y, int flag); 
main()
{
      float a,b,c;
      float minNum,maxNum; 
      printf("Please input three float/int numbers:\n"); 
      scanf("%f %f %f",&a,&b,&c); 
      printf("The three numbers you input are: %f %f %f\n",a,b,c); 
      minNum=compTwo(compTwo(a,b,0),c,0);
      maxNum=compTwo(compTwo(a,b,1),c,1); 
      printf("The minmun number you input is: %f\n",minNum); 
      printf("The maxmum number you input is: %f\n",maxNum); 
      system("pause"); 

float compTwo(float x, float y, int flag) 
{
      if(flag==0) 
      {
         return x<y?x:y;     //return the small number 
      }
      else if(flag==1) 
      {
          return x<y?y:x;    //return the large number 
      }
      else
      {
          printf("Error: \"flag\" in compTwo() has a problem!\n"); 
      }