Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MINUS_NINE_NINE_NINE -999
  4. int main(void)
  5. {
  6.     int num = 0;
  7.     int firstMax = MINUS_NINE_NINE_NINE;
  8.     int secondMax = MINUS_NINE_NINE_NINE;
  9.     int oldFirstMax = MINUS_NINE_NINE_NINE;
  10.     //declaring vars
  11.     while(num!=MINUS_NINE_NINE_NINE)
  12.     {
  13.         printf("Enter number(-999 to end): ");
  14.         scanf("%d",&num);
  15.         getchar();
  16.         //getting a number from the user
  17.         if (num > firstMax)
  18.         {
  19.             oldFirstMax = firstMax;
  20.             firstMax = num;
  21.             secondMax = oldFirstMax;
  22.         }
  23.         /*
  24.         if number is bigger than the first max ,
  25.         old first max will be equal to the old number ,
  26.         new first max will be equal to the current number ,
  27.         second max will be equal to the old first max.
  28.         */
  29.         else if(num > secondMax)
  30.         {
  31.             secondMax = num;
  32.         }
  33.         /*
  34.         if number isn't bigger than first max but is bigger than second max,
  35.         second max will be equal to the current number.
  36.         */
  37.     }
  38.     printf("First max: %d, Second max: %d",firstMax,secondMax);
  39.     //printing the first max and the second max
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement