Selasa, 30 Juni 2015

Program c++ konversi angka ke huruf

#include <iostream.h>
#include <conio.h>
void satuan (long a)
{
if (a==1) {
cout<<" Satu ";
}
else if (a==2) {
cout<<" Dua ";
}
else if (a==3) {
cout<<" Tiga ";
}
else if (a==4) {
cout<<" Empat ";
}
else if (a==5) {
cout<<" Lima ";
}
else if (a==6) {
cout<<" Enam ";
}
else if (a==7) {
cout<<" Tujuh ";
}
else if (a==8) {
cout<<" Delapan ";
}
else if (a==9) {
cout<<" Sembilan ";
}
else if (a==10) {
cout<<" Sepuluh ";
}
else if (a==11) {
cout<<" Sebelas ";
}
}
void terbilang (long b)
{
if (b<=11) {
satuan(b);
}
else if ((b>11) && (b<=19)) {
terbilang(b%10);
cout<<"Belas ";
}
else if ((b>=20)&&(b<=99)) {
terbilang(b/10);
cout<<"Puluh";
terbilang(b%10);
}
else if ((b>=100)&&(b<=199)) {
cout<<"Seratus";
terbilang(b%100);
}
else if ((b>=200)&&(b<=999)) {
terbilang(b/100);
cout<<"Ratus";
terbilang(b%100);
}
else if ((b>=1000)&&(b<=1999)) {
cout<<"Seribu";
terbilang(b%1000);
}
else if ((b>=2000)&&(b<=9999)) {
terbilang(b/1000);
cout<<"Ribu";
terbilang(b%1000);
}
else if ((b>=10000)&&(b<=99999)) {
terbilang(b/1000);
cout<<"Ribu";
terbilang(b%1000);
}
else if ((b>=100000)&&(b<=999999)) {
terbilang(b/1000);
cout<<"Ribu";
terbilang(b%1000);
}
else if ((b>100000))
{
cout<<"maaf! angka yang kamumasukanterlalubanyak";
}
}
int main()
{
int nilai;
cout<<"\t\t\t=====MUHAMMAD SONNY HARSONO=====\n";
cout<<"\t\t\t   =====011401503125063=====\n";
cout<<"\t\t\t\t=====ALGORITMA=====\n";
cout<<"\t\t\t\t     ''ARRAY''\n";
cout<<"\nInputbilangan:";cin>>nilai;
if (nilai<0){
cout<<"Minus ";
terbilang(nilai);
} else {
terbilang(nilai);
}
getch();
}

5 komentar:

  1. cara nulis pake matlab gimana formatnya?

    BalasHapus
    Balasan
    1. untuk matlab sendiri dia ada editornya ko, format matlab itu m file

      Hapus
  2. Gan mau tanya sakumpama saya mau buat program , trus harus menginputkan nama dan namanya itu huruf tidak boleh angka atau simbol . Itu gimana ya

    BalasHapus
  3. Gan mau tanya sakumpama saya mau buat program , trus harus menginputkan nama dan namanya itu huruf tidak boleh angka atau simbol . Itu gimana ya

    BalasHapus