Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MINUS_NINE_NINE_NINE -999
- int main(void)
- {
- int num = 0;
- int firstMax = 0;
- int secondMax = 0;
- int oldFirstMax = 0;
- //declaring vars
- while(num!=MINUS_NINE_NINE_NINE)
- {
- printf("Enter number(-999 to end): ");
- scanf("%d",&num);
- getchar();
- //getting a number from the user
- if (num > firstMax)
- {
- oldFirstMax = firstMax;
- firstMax = num;
- secondMax = oldFirstMax;
- }
- /*
- if number is bigger than the first max ,
- old first max will be equal to the old number ,
- new first max will be equal to the current number ,
- second max will be equal to the old first max.
- */
- else if(num > secondMax)
- {
- secondMax = num;
- }
- /*
- if number isn't bigger than first max but is bigger than second max,
- second max will be equal to the current number.
- */
- }
- printf("First max: %d, Second max: %d",firstMax,secondMax);
- //printing the first max and the second max
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement