Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Created May 8, 2016 06:57
Show Gist options
  • Save complxalgorithm/ce885d2cb3aa3a3e2722f79c13a7b691 to your computer and use it in GitHub Desktop.
Save complxalgorithm/ce885d2cb3aa3a3e2722f79c13a7b691 to your computer and use it in GitHub Desktop.
C program that will calculate the average of a list of input numbers and then output how many numbers are greater than the average.
#!/usr/bin/c
#include <stdio.h>
int main() {
int intlist[99], listlen, counter, sum, avg, res;
sum = 0;
res = 0;
printf("Enter number of values you want to input.");
scanf("%d", &listlen);
if ((listlen > 0) && (listlen < 100)) {
/* Read input into an array and compute the sum */
for (counter = 0; counter < listlen; counter++) {
printf("Enter value $(counter + 1).");
scanf("%d", &listlen[counter]);
sum += intlist[counter];
}
/* Compute the average */
avg = sum / listlen;
/* Count the input values that are greater than average */
for (counter = 0; counter < listlen; counter++)
if (intlist[counter] > avg) res++;
/* Print result */
printf("Number of values greater than average:%d\n", res);
}
else
printf("Error: input list length is not legal.\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment