Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- void chart(int count, int scores[]);
- int main(void)
- {
- int n=0;
- n = get_int("How many numbers? ");
- int scores[n];
- //get scores
- for (int i=0; i<n; i++)
- {
- scores[i] = get_int("Enter score #%i: ",i+1);
- }
- int total=0;
- //total the scores
- for (int i=0; i<n; i++)
- {
- total = total + scores[i];
- }
- //calc average
- float avg=0;
- avg = (float)total / n;
- printf("Avg = %f\n",avg);
- chart(n, scores);
- }
- void chart(int count, int scores[])
- {
- //Loop thru each test score
- for (int i=0; i<count; i++)
- {
- printf("%i: ", scores[i]);
- for (int j=0; j<scores[i]; j++)
- {
- printf("*");
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement