Conditional Statements Structure Question

Posted on 2006-03-23
Last Modified: 2010-04-15
Hello Experts,

I'm trying to help my daughter with her C homeowork.  I'm a longtime developer but have not worked in C in decades.  She has the following problem:

The mathematical operation min(x,y) can be represented by the conditional

     (x < y) ? x : y

   In similar fashion, using only conditional expressions, describe the
   mathematical operations:

   min(x, y, z)             and          max(x,y,z,w)

I understand how the min(x,y) translate into (x < y) ? x : y
 and that (x < y) ? x : y  is tha same as If x < y then x else y
but am drawing a blank as to how to code the two problems.

Can anyone help?

Question by:Waterstone
    LVL 6

    Expert Comment

    (x<y) ? ((x < z) ? x : z) : ((y < z) ? y : z) ;

    i hope this works....
    the same way you can write to max(x,y,z,w)

    LVL 20

    Accepted Solution

    hi Waterstone,

    as you wrote:

    min2(x,y)   (x < y) ? x : y;


    min3(x,y,z)   min2( min2( x, y ), z );


    max4( x, y, z, w )    max2( max2( max2( x, y ), z ), w );

    hope it helps
    LVL 45

    Expert Comment

    #include <stdio.h>

    int main()
          int i=10,j=3,k=12,l=9;
          int max,min;

          min = (i<j)?((i<k)?i:k):((j<k)?j:k);

          max = (j>i)?((j>k)?(j>l?j:l):(k>l?k:l)):((i>k)?(i>l?i:l):(k>l?k:l));

          printf("min %d max %d",min,max);

    LVL 8

    Expert Comment

    by:deepu chandran
    u can write the solution for finding minimam of N number,
    first u hav to pass the numbers into the array
    pass the array and the no. arg over the function named min
    the function is like this,
    int min(int arr[20],int noarg)  //arr[20]  is the array which are having no.//noarg  is the no. arguments
       int i,min=arr[0];
       return min;
    LVL 16

    Expert Comment

    Hi Waterstone,

    They're probably looking for something like:

    #define Min(x,y) ((x)<(y)?(x):(y))
    #define Min3(x,y,z) (Min(x,y)<(z)?Min(x,y):(z))


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Which checksum is this? 7 132
    Adjust Mfcapp 29 143
    how to understand recursion 12 193
    distributed computing in Python 4 91
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now