Pemrograman : Menghitung Jumlah Kalimat

#include<stdio.h>

#include<string.h>

struct hitung{

char kata[20];

int jumlah;

};

main()

{

struct hitung kalimat[6];

int i,j,tanda;

char *y[]={“saya”,”kamu”,”aku”,”kamu”,”dia”,”engkau”};

for(i=0;i<6;i++)

kalimat[i].jumlah=0;

for(i=0;i<6;i++)

{

tanda=0;

for(j=0;j<6;j++)

{

if(strcmpi(kalimat[j].kata,y[i])==0)

tanda++;

}

if(tanda==0)

{

strcpy(kalimat[i].kata,y[i]);

}

}

for(i=0;i<6;i++)

{

for(j=0;j<6;j++)

{

if(strcmpi(kalimat[i].kata,y[j])==0)

kalimat[i].jumlah++;

}

}

for(i=0;i<6;i++)

{

if(kalimat[i].jumlah!=0)

{

printf(“%s=%d\n”,kalimat[i].kata,kalimat[i].jumlah);

}

}

}

Output :

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s