sumber gambar: sdtimes.com
#include <iostream>
using namespace std;
int main()
{
char garis[150];
int vokal, konsonan, angka, spasi;
vokal = konsonan = angka = spasi = 0;
cout << "masukkan kalimat disini: ";
cin.getline(garis, 150);
for(int i = 0; garis[i]!='\0'; ++i)
{
if(garis[i]=='a' || garis[i]=='e' || garis[i]=='i' ||
garis[i]=='o' || garis[i]=='u' || garis[i]=='A' ||
garis[i]=='E' || garis[i]=='I' || garis[i]=='O' ||
garis[i]=='U')
{
++vokal;
}
else if((garis[i]>='a'&& garis[i]<='z') || (garis[i]>='A'&& garis[i]<='Z'))
{
++konsonan;
}
else if(garis[i]>='0' && garis[i]<='9')
{
++angka;
}
else if (garis[i]==' ')
{
++spasi;
}
}
cout << "jumlah vokal: " << vokal << endl;
cout << "jumlah konsonan: " << konsonan << endl;
cout << "jumlah angka: " << angka << endl;
cout << "jumlah spasi: " << spasi << endl;
return 0;
}
Sumber Pustaka : programiz.com
0 komentar: