您的位置:首页 > 其它

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

2012-08-08 18:29 239 查看
//////////////////////////////////////////////////////

//求三个数的最大值和最小值 

///////////////////////////////////////////////////// 

#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"); 

      } 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c float numbers input system
相关文章推荐