49 lines
1.7 KiB
C
49 lines
1.7 KiB
C
#include <stdio.h>
|
|
|
|
#define COUNT_CHANNELS 10
|
|
#define ZERO 0
|
|
#define ONE 1
|
|
#define TWO 2
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// Exercise 6
|
|
// ----------
|
|
//
|
|
// General : The program counts several channels above the average viewing percentage.
|
|
//
|
|
// Input : 40 numbers (0 - 100) (unsigned short).
|
|
//
|
|
// Process : The program calculates the average viewing percentage, and counts how
|
|
// many channels are in the field above average.
|
|
//
|
|
// Output : Number of channels above average viewership percentage.
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programmer : Cohen Idan
|
|
// Student No : 211675038
|
|
// Date : 23.10.2019
|
|
//---------------------------------------------------------------------------------------
|
|
void main(void)
|
|
{
|
|
unsigned short channels[COUNT_CHANNELS] = { ZERO },
|
|
counter,
|
|
percent,
|
|
sum = ZERO,
|
|
avg,
|
|
counter = ZERO;
|
|
for (counter = ZERO; counter < COUNT_CHANNELS; counter++)
|
|
{
|
|
printf("Enter percet of viewers: ");
|
|
scanf("%hd", &percent);
|
|
channels[counter] = percent;
|
|
}
|
|
|
|
for (counter = ZERO; counter < COUNT_CHANNELS; counter++)
|
|
sum += channels[counter];
|
|
|
|
// According to the second section "avg" should be changed to 20
|
|
avg = sum / COUNT_CHANNELS;
|
|
for (counter = ZERO; channels[counter] > avg; counter++);
|
|
|
|
printf("Above avg: %hd\n", counter);
|
|
} |