Berikut merupakan script program yang diperlukan :
========================================================================
#include <iostream>
using namespace std;
int main ()
{
char huruf[52]={'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 jumlah[52]={0};
int n;
cout<<"Masukan Karakter yang akan dihitung : ";cin>>n;
char x;
int i=1;
while(i<=n)
{cout<<"Masukan Karakter ke-"<<i<<" : ";cin>>x;
for(int a=0; a<52; a++)
{ if (x == huruf [a])
{jumlah[a]++;} }
i++;}
for(int i=0; i<52; i++)
{
if (jumlah[i]!=0)
{cout<< "Frekuensi huruf " <<huruf[i]<< " : " <<jumlah[i]<<endl;}
}
return 0;
}
========================================================================
Output Program :
========================================================================
#include <iostream>
using namespace std;
int main ()
{
char huruf[52]={'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 jumlah[52]={0};
int n;
cout<<"Masukan Karakter yang akan dihitung : ";cin>>n;
char x;
int i=1;
while(i<=n)
{cout<<"Masukan Karakter ke-"<<i<<" : ";cin>>x;
for(int a=0; a<52; a++)
{ if (x == huruf [a])
{jumlah[a]++;} }
i++;}
for(int i=0; i<52; i++)
{
if (jumlah[i]!=0)
{cout<< "Frekuensi huruf " <<huruf[i]<< " : " <<jumlah[i]<<endl;}
}
return 0;
}
========================================================================
Output Program :
Tidak ada komentar:
Posting Komentar