Menghitung Huruf dengan Java

#include <stdio.h>

#include <string.h>

#include <conio.h>

 

#define STRSIZE 50

#define KARSIZE 52

 

char kar[KARSIZE] =

{‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’,

‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’,

‘y’, ‘z’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’,

‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’,

‘W’, ‘X’, ‘Y’, ‘Z’};

int jml[KARSIZE] = {0};

char str[STRSIZE];

 

void hitung(void);

 

int main(void) {

printf(“Masukkan kata: “);

scanf(“%s”, str);

 

hitung();

getch();

 

return 0;

}

 

void hitung(void) {

int l = strlen(str);

int i, j;

 

for(i = 0; i < l; i++) {

for(j = 0; j < KARSIZE; j++) {

if(kar[j] == str[i]) {

jml[j]++;

}

}

}

printf(“Jumlah huruf\n”);

 

for(j = 0; j < KARSIZE; j++) {

if(jml[j] > 0) {

printf(”  %c: %d\n”, kar[j], jml[j]);

}

}

}

Tag:

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: