Skip to content

Instantly share code, notes, and snippets.

@rawaid
Created February 4, 2014 15:35
Show Gist options
  • Save rawaid/8805964 to your computer and use it in GitHub Desktop.
Save rawaid/8805964 to your computer and use it in GitHub Desktop.
// C# Example Program
// Input: An integer, listlen, where listlen is less than // 100, followed by listlen-integer values.
// Output: The number of input values that are greater
// than the average of all input values.
using System;
public class Ch2example {
static void Main() { int[] intlist;
int listlen,
counter,
sum = 0,
average,
result = 0;
intList = new int[99];
listlen = Int32.Parse(Console.readLine()); if ((listlen > 0) && (listlen < 100)) {
// Read input into an array and compute the sum
for (counter = 0; counter < listlen; counter++) {
intList[counter] =
Int32.Parse(Console.readLine());
sum += intList[counter];
} //- end of for (counter ...
// Compute the average
average = sum / listlen;
// Count the input values that are > average foreach (int num in intList)
if (num > average) result++; // Print result
Console.WriteLine(
"Number of values > average is:" + result);
} //- end of if ((listlen ...
else
Console.WriteLine(
"Error--input list length is not legal");
} //- end of method Main
} //- end of class Ch2example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment