Files
college-C/4/ex4.c
2022-02-25 15:33:16 +02:00

44 lines
1.3 KiB
C

#include <stdio.h>
#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
#define ONE 1
#define ZERO 0
#define TEN 10
//---------------------------------------------------------------------------------------
// Exercise 4
// ----------
//
// General : The program receives 10 numbers and prints the largest
// number and the second largest number.
//
// Input : 10 numbers.
//
// Process : The program loop for input and check max and second max .
//
// Output : 2 number.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 23.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned int num,
counter,
temp,
max_max = ZERO,
min_max = ZERO;
for (counter = ZERO; counter < TEN; counter++)
{
printf("Enter number: ");
scanf("%d", &num);
(num > max_max) ? (min_max = max_max, max_max = num) : (min_max = MAX(min_max, num));
}
printf("Max_Max: %d\nMin_Max: %d\n", max_max, min_max);
}