#include <stdio.h>
void histogram(char *);
int main() {
char str[50];
printf("\n\tDigite uma frase: "); histogram(str);
}
void histogram(char *frase) {
int num=0, num2=0, az=0;
char alfabeto[]="abcdefghijklmnopqrstuvwxyzçABCDEFGHIJKLMNOPQRSTUVWXYZÇ";
int contagens[256];
for (num= 0; num < 256; ++num){
contagens[num]=0;
}
for(num = 0; frase[num] != 0; num++) {
for (num2 = 0; alfabeto[num2] != '\0'; ++num2){
char letra = frase[num];
if (letra == alfabeto[num2]){
contagens[(int)letra]++;
az++;
break;
}
}
}
printf("\n\n\tTemons %d letras\n\n", az
); for (num = 0; num < 256; ++num){
if (contagens[num] > 0){
printf("\n%c: %d", (char)num
, contagens
[num
]); }
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGhpc3RvZ3JhbShjaGFyICopOwoKaW50IG1haW4oKSB7CgljaGFyIHN0cls1MF07CgoJcHJpbnRmKCJcblx0RGlnaXRlIHVtYSBmcmFzZTogIik7CglmZ2V0cyhzdHIsNTAsc3RkaW4pOwoJaGlzdG9ncmFtKHN0cik7Cgp9Cgp2b2lkIGhpc3RvZ3JhbShjaGFyICpmcmFzZSkgewoJaW50IG51bT0wLCBudW0yPTAsIGF6PTA7CgljaGFyIGFsZmFiZXRvW109ImFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6w6dBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWsOHIjsKCWludCBjb250YWdlbnNbMjU2XTsKCWZvciAobnVtPSAwOyBudW0gPCAyNTY7ICsrbnVtKXsKICAgICAgICBjb250YWdlbnNbbnVtXT0wOwoJfQoKCWZvcihudW0gPSAwOyBmcmFzZVtudW1dICE9IDA7IG51bSsrKSB7CiAgICAgICAgZm9yIChudW0yID0gMDsgYWxmYWJldG9bbnVtMl0gIT0gJ1wwJzsgKytudW0yKXsKICAgICAgICAgICAgY2hhciBsZXRyYSA9IGZyYXNlW251bV07CiAgICAgICAgICAgIGlmIChsZXRyYSA9PSBhbGZhYmV0b1tudW0yXSl7CiAgICAgICAgICAgICAgICBjb250YWdlbnNbKGludClsZXRyYV0rKzsKICAgICAgICAgICAgICAgIGF6Kys7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgIH0KCX0KCglwcmludGYoIlxuXG5cdFRlbW9ucyAlZCBsZXRyYXNcblxuIiwgYXopOwoJZm9yIChudW0gPSAwOyBudW0gPCAyNTY7ICsrbnVtKXsKICAgICAgICBpZiAoY29udGFnZW5zW251bV0gPiAwKXsKICAgICAgICAgICAgcHJpbnRmKCJcbiVjOiAlZCIsIChjaGFyKW51bSwgY29udGFnZW5zW251bV0pOwogICAgICAgIH0KCX0KfQo=