Created
November 29, 2018 00:07
-
-
Save andrefreitas/17c84f5d6fc8384f699cfbd8da959e96 to your computer and use it in GitHub Desktop.
notes.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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