KAR98S

Group and frequency.c

Jan 26th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. //Group and frequency question, input restricted between 0 and 100 and it automatically takes random input
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. typedef unsigned int    UINT;
  7.  
  8. int main() {
  9.     UINT arr[99] = { 0 }, aSize = 0;
  10.     UINT sort[11] = { 0 }, sSize = 11;
  11.     srand((UINT)time(NULL));
  12.     {   //Init ---IGNORE---
  13.         aSize = 20;
  14.         for (int i = 0; i < aSize; i++) {
  15.             arr[i] = rand() % 100;
  16.         }
  17.     }
  18.  
  19.     printf("Elements: ");
  20.     for (int i = 0; i < aSize; i++) {
  21.         printf("%d, ", arr[i]);
  22.     }
  23.  
  24.     for (int i = 0; i < aSize; i++) {
  25.         sort[arr[i] / 10]++;
  26.     }
  27.  
  28.     printf("\n\n      range\t\tFrequency");
  29.  
  30.     for (int i = 0; i < sSize; i++) {
  31.         printf("\n  %d\tto\t%d\t    %d", i * 10, i * 10 + ((i == 10) ? 0 : 9), sort[i]);
  32.     }
  33.  
  34.     return 0;
  35. }
Add Comment
Please, Sign In to add comment