First Upload
This commit is contained in:
44
4/ex4.c
Normal file
44
4/ex4.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user