#include <ctype.h>
#include <stdio.h>
#include <string.h>

int gcd(int a, int b) {
	int r;
	
	while (a != 0) {
		r = b % a;
		b = a;
		a = r;
	}

	return b;
}

int main() {
	char msg[500];
	int i, freq[26];

	printf("Please enter the message:\n");
	scanf("%s",msg);
	
	//initializing the frequency array
	for (i = 0; i < 26; i++)
		freq[i] = 0;

	int length = (int) strlen(msg);

	//populating the frequency array
	for (i = 0; i < length; i++) {
		int val = tolower(msg[i]) - 97;
		
		if (val >= 0 && val < 26)
			freq[val]++;
	}

	//printing the letter frequencies
	printf("Letter\tFrequency\n");
	for (i = 0; i < 26; i++) {
		printf("%c\t%d\n", i+97, freq[i]);
	}

	//calculating the IC as a fraction
	int top = 0, bottom = length*(length-1);

	for (i = 0; i < 26; i++)
		top += freq[i]*(freq[i]-1);

	//reducing the IC fraction
	int factor = gcd(top, bottom);
	top /= factor;
	bottom /= factor;

	//printing the information
	printf("\nIC as fraction: %d/%d\nIC as decimal: %lf\n", top, bottom, ((double)top)/bottom);

	return 0;
}



