thenewboston

C Programming Tutorial - 48 - Creating an Expandable Program

Aug 22nd, 2014
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int i, howMany;
  7.     int total = 0;
  8.     float average = 0.0;
  9.     int * pointsArray;
  10.  
  11.     printf("How many numbers do you want to use?\n");
  12.     scanf(" %d", &howMany);
  13.  
  14.     pointsArray = (int *) malloc(howMany * sizeof(int));
  15.  
  16.     printf("Enter them hoss!\n");
  17.  
  18.     for(i=0; i<howMany; i++){
  19.         scanf(" %d", &pointsArray[i]);
  20.         total += pointsArray[i];
  21.     }
  22.  
  23.     average = (float)total / (float)howMany;
  24.     printf("Average is %f", average);
  25.  
  26.     free(pointsArray);
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment