Use scanf to read data into array


Levels of difficulty: / perform operation:


Program

#include <stdio.h>

int main(void)
{
  int numbers[10];
  int count = 10;
  long sum = 0L;
  float average = 0.0f;

  printf("\nEnter the 10 numbers:\n");
  int i;

  for(i = 0; i < count; i ++)
  {
    printf("%2d> ",i+1);
    scanf("%d", &numbers[i]);
    sum += numbers[i];
  }

  average = (float)sum/count;

  printf("\nAverage of the ten numbers entered is: %f\n", average);
  return 0;
}


Result

Enter the 10 numbers:
      1> 2
      2> 3
      3> 1
      4> 2
      5> 1
      6> 1
      7> 1
      8> 2
      9> 1
     10> 1
     
     Average of the ten numbers entered is: 1.500000