Skip to content

Instantly share code, notes, and snippets.

@andrefreitas
Created November 29, 2018 00:07
Show Gist options
  • Save andrefreitas/17c84f5d6fc8384f699cfbd8da959e96 to your computer and use it in GitHub Desktop.
Save andrefreitas/17c84f5d6fc8384f699cfbd8da959e96 to your computer and use it in GitHub Desktop.
notes.c
#include <stdio.h>
float computeAverage(int *notes, int length) {
float sum = 0;
for(int i = 0; i < length; i++) {
sum += notes[i];
}
return sum / length;
}
int askLength() {
int length;
printf("Number of notes: ");
scanf("%d", &length);
return length;
}
void readNotes(int *notes, int length) {
for(int i = 0; i < length; i++) {
printf("Note: ");
scanf("%d", notes + i);
}
}
int main() {
int length = askLength();
int notes[length];
readNotes(notes, length);
float average = computeAverage(notes, length);
printf("Average: %f\n", average);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment