Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // z5207462 ashish mathew
- // Write a C program frequency_analysis.c which
- // reads characters from its input until end of input.
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 1000
- #define LETTERS 26
- int main (void) {
- char letters[MAX]; // array for storing letters
- int counter[MAX] = {0};// array for storing amount of letters
- double total = 0;
- int alphabet_position;
- int character = getchar();
- int i = 0;
- // Check for lowercase letters
- while (character != EOF && i < MAX) {
- if (character >= 'a' && character <= 'z') {
- letters[i] = character;
- total = total + 1;
- alphabet_position = character - 'a';
- counter[alphabet_position] = counter[alphabet_position] + 1;
- }
- else if (character >= 'A' && character <= 'Z') {
- letters[i] = character;
- total = total + 1;
- alphabet_position = character - 'A';
- counter[alphabet_position] = counter[alphabet_position] + 1;
- }
- character = getchar();
- i++;
- }
- int j = 0;
- while (j < LETTERS) {
- printf ("'%c' %lf %d\n", j +'a', counter[j]/total, counter[j]);
- j++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement