Print the average of the 1,000 variables before printing the individual values. - C Array

C examples for Array:Array Element

Description

Print the average of the 1,000 variables before printing the individual values.

Demo Code

#include <stdio.h>
#include <stdlib.h>

int main( void ){
 
   int random[1000];
   int a, b, c;//from  w ww . java  2  s  . c  o m
   long total = 0;

   for (a = 0; a < 1000; a++){
      random[a] = rand();
      total += random[a];
   }
   printf("\n\nAverage is: %ld\n",total/1000);

   for (a = 0; a < 1000; a++){
      printf("\nrandom[%d] = ", a);
      printf("%d", random[a]);

      if ( a % 10 == 0 && a > 0 ){
         printf("\nPress Enter to continue, CTRL-C to quit.");
         getchar();
      }
   }
   return 0;
}

Result


Related Tutorials