Advertisement
DarthLucius

average_array

Jun 20th, 2022 (edited)
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <time.h>
  3.  
  4. int main(){
  5.     int n, sum = 0; // say, cem
  6.     printf("Ededlerin sayini daxil edin: ");
  7.     scanf("%d", &n);
  8.     int arr[n];
  9.     srand(time(0));
  10.  
  11.     printf("Array: [");
  12.     for(int i = 0; i < n; i++){
  13.         arr[i] = rand() % 100 + 1;
  14.         printf("%d", arr[i]);
  15.         if(i != (n - 1)){
  16.             printf(", ");
  17.         }
  18.     }
  19.     printf("]\n");
  20.  
  21.     for(int i = 0; i < n; i++){
  22.         sum += arr[i];
  23.     }
  24.  
  25.     float avg = (float)sum / (float)n; // ededi orta
  26.     printf("%f\n", avg);
  27.     system("pause");
  28.  
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement