daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // z5207462 ashish mathew
  2.  
  3. // Write a C program frequency_analysis.c which
  4. // reads characters from its input until end of input.
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. #define MAX 1000
  10. #define LETTERS 26
  11.  
  12. int main (void) {
  13.     char letters[MAX]; // array for storing letters
  14.     int counter[MAX] = {0};// array for storing amount of letters
  15.    
  16.  
  17.     double total = 0;
  18.     int alphabet_position;
  19.     int character = getchar();
  20.  
  21.    
  22.  
  23.     int i = 0;
  24. // Check for lowercase letters
  25.     while (character != EOF && i < MAX) {  
  26.         if (character >= 'a' && character <= 'z') {
  27.             letters[i] = character;
  28.             total = total + 1;
  29.             alphabet_position = character - 'a';
  30.             counter[alphabet_position] = counter[alphabet_position] + 1;
  31.         }
  32.         else if (character >= 'A' && character <= 'Z') {
  33.             letters[i] = character;
  34.             total = total + 1;
  35.             alphabet_position = character - 'A';
  36.             counter[alphabet_position] = counter[alphabet_position] + 1;
  37.         }
  38.        
  39.         character = getchar();
  40.         i++;
  41.     }
  42.     int j = 0;
  43.     while (j < LETTERS) {
  44.         printf ("'%c' %lf %d\n", j +'a', counter[j]/total, counter[j]);
  45.         j++;
  46.     }
  47. return 0;
  48.  
  49. }
RAW Paste Data
Top