Skip to content

Instantly share code, notes, and snippets.

@albert-chang0
Created August 8, 2011 23:10
Show Gist options
  • Save albert-chang0/1133005 to your computer and use it in GitHub Desktop.
Save albert-chang0/1133005 to your computer and use it in GitHub Desktop.
Solution
#include <stdio.h>
#include <stdlib.h>
double avg(int[], int);
double avg(int nums[], int count)
{
int i, sum = 0;
for (i = 0; i < count; ++i)
{
sum += nums[i];
}
return (double)sum / count;
}
int main(int argc, const char *argv[])
{
int i, nums[argc - 1];
for (i = 1; i < argc; ++i)
nums[i - 1] = atoi(argv[i]);
printf("%f\n", avg(nums, argc - 1));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment