Thread: finding maximum munber

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Exclamation finding maximum munber

    a=1 b=2 c=3
    how can i find max,min numbers in c without using arrays just if statement

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    Code:
    int high, num, low = 0;
    
    while (test condition)
        if (num > high)
            high = num;
    
        if (num < low)
            low = num;
    
        //grab next value of num from file, stdin, etc...
    }
    http://www.KBeutler.com

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Angry but i have 3 munbers not 2

    this function is works if i have 2 variables but i have 3 variables a,b,c

  4. #4
    Unregistered
    Guest
    but if one of the numbers is minus (-4)
    so the LOW is not the low

    if (a>b && a>C)
    max = a;

    else if (b>a && b>c)
    max=b;
    else max=c;

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    my code doesnt work

    #include <conio.h>
    #include <stdio.h>
    int a,b,c,max,min,av;

    void main() {
    clrscr();
    printf("1.number:");
    scanf("%d",&a);
    printf("2.number:");
    scanf("%d",&b);
    printf("3.number:");
    scanf("%d",&c);
    //---------------------------- max number
    if(a>b && a>c)
    a=max;
    else if(b>a && b>c)
    b=max;
    else
    c=max;
    //------------------------------- min number
    if(a<b && a<c)
    a=min;
    else if(b<a && b<c)
    b=min;
    else
    c=min;
    //-----------------------------//between max and min
    if(a==min && c==max || a==max && c==min)
    b=av;
    else if(b==min && c==max || b==max && c==min)
    a=av;
    else
    c=av;

    printf("max=\n",max);
    printf("min=\n",min);
    printf("av=\n",av);
    getch();
    }


    what is wrong here??

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    10

    Cool got it

    here is the correct code


    #include <conio.h>
    #include <stdio.h>
    int a,b,c,max,min,av;

    void main() {
    clrscr();
    printf("1.number:");
    scanf("%d",&a);
    printf("2.number:");
    scanf("%d",&b);
    printf("3.number:");
    scanf("%d",&c);
    //---------------------------- max number
    if(a>b && a>c)
    max=a;
    else if(b>a && b>c)
    max=b;
    else
    max=c;
    //------------------------------- min number
    if(a<b && a<c)
    min=a;
    else if(b<a && b<c)
    min=b;
    else
    min=c;
    //-----------------------------//between max and min
    if((a==min && c==max || a==max && c==min))
    av=b;
    else if((b==min && c==max )||( b==max && c==min))
    av=a;
    else
    av=c;

    printf("max=%d\n",max);
    printf("min=%d\n",min);
    printf("av=%d\n",av);
    getch();
    }


    you made a mistake by assigning a=max ,as max at that moment contain no value so you are assigning a=0. and same is the case with av and min.

    another mistake was the %d sign you did not put that in the last printf statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-28-2009, 09:58 PM
  2. finding the second maximum.
    By lbillys in forum C Programming
    Replies: 6
    Last Post: 05-18-2009, 08:23 PM
  3. Replies: 10
    Last Post: 04-26-2009, 02:46 PM
  4. Finding the maximum in an array
    By Turtal in forum C Programming
    Replies: 4
    Last Post: 11-15-2006, 07:07 AM
  5. Finding maximum queue length
    By crepincdotcom in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-05-2004, 09:31 AM