Adblock breaks this site

:D

Discussion in 'Programming General' started by PsychicFreak, Aug 21, 2010.

  1. PsychicFreak

    PsychicFreak Member

    Joined:
    Jun 6, 2008
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0
    :D

    guys how to make a c program that will get the maximum and minimum number of 5 variables?
     
  2. Fastshot

    Fastshot Forum Addict

    Joined:
    Apr 3, 2010
    Posts:
    364
    Referrals:
    0
    Sythe Gold:
    0
    :D

    it will be something like:

    Code:
    // put in main
    int numbers[10]; //array stores the number values
    int x;
    int highest = 0;
    int lowest = 20000;
    
    for (x = 0; x < 10; x++)
    {
         if (highest < numbers[x]) highest = numbers[x];
         if (lowest > numbers[x]) lowest = numbers[x];
    
    }
    
    printf("%d %d", highest, lowest);
    
    I'm a newbie in c, but this should work.
     
< how to get the minimum value | All Ready Rsps >


 
 
Adblock breaks this site