Advertisement
volkovich_maksim

symbol_freq

Sep 14th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(void){
  5.     float abs_freq[256];
  6.     int i,chr,count = 0;
  7.    
  8.     for (i = 0; i < 255; i++)
  9.         abs_freq[i] = 0;
  10.  
  11.     while ((chr = getchar()) != EOF){
  12.         abs_freq[(int)chr]++;
  13.         count++;
  14.     }
  15.  
  16.     for (i = 0; i < 255; i++){
  17.         if (abs_freq[i] != 0){
  18.             if (i == '\n'){
  19.                 printf("\n\\n");
  20.                 printf("   absolute frequency  %3.0f", abs_freq[i]);
  21.                 printf("   relative frequency  %0.3f", abs_freq[i]/count);
  22.             }
  23.             if (i == '\t'){
  24.                 printf("\n\\t");
  25.                 printf("   absolute frequency  %3.0f", abs_freq[i]);
  26.                 printf("   relative frequency  %0.3f", abs_freq[i]/count);
  27.             }
  28.             if (i != '\n' && i != '\t'){
  29.                 printf("\n %c", i);
  30.                 printf("   absolute frequency  %3.0f", abs_freq[i]);
  31.                 printf("   relative frequency  %1.3f", abs_freq[i]/count);
  32.             }
  33.         }
  34.     }
  35.     printf("\n");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement