You are on page 1of 13

1. Program menghitung jumlah huruf yang dominan.

Program
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char kata[100],t1,t2,t3,i,j;
int b1=0;
cout<<"=========================================================
========"<<endl;
cout<<" Program Menentukan Huruf Terbanyak Dari Suatu Kata "<<endl;
cout<<"=========================================================
========"<<endl<<endl<<endl;
cout<<"Masukkan kata : ";
cin>>kata;
int h=strlen(kata);
for (i=0;i<h;i++)
{
int jum=0;
for(j=0;j<h;j++)
{
t1=kata[i];
t2=kata[j];
if(t1==t2)
{
jum++;
}
}
if(b1<jum)
{
t3=t1;
b1=jum;
}
}
cout<<endl;
cout<<"Huruf terbanyak adalah : "<<t3<<" "<<endl;
return 0;
cout<<endl<<endl;
}
Hasil Program
Flowchart
Start.

Kata,h,
b1=0

True
i=0 to h

jum=0

True
j=0 to h

t1=kata[i]
t2=kata[j]

Ya
jum++
t1==t2

Tidak

j++

False Ya
t3=t1
b1<ju
b1=jum
Tidak

i++

False

End.
t3 return 0
2. Program mengurutkan bilangan terbesar ke terkecil dengan iteratif
Flowchart
Start.

True
x=0 to n

a[x]

x++
False

x=0 to n
True

True
y=x to n

Ya
b=a[x]
a[x]<a[y] a[x]=a[y]
a[y]=b
Tidak

y++
False

x++
False
True
x=0 to n

a[x]

False
End.
x++
Program
#include<iostream>
using namespace std;
int main()
{
int a[100],n,x,y,b;
cout<<"==================================================="<<endl;
cout<<"| Program Mengurutkan Bilangan Terbesar ke Terkecil |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<"========================================="<<endl<<endl<<endl;
cout<<"Masukkan Banyaknya Angka : ";cin>>n;
cout<<endl<<endl;
for(x=1;x<=n;x++)
{
cout<<"Masukkan angka ke- "<<x<<" : "; cin>>a[x];
}
for(x=1;x<=n;x++)
{
for(y=x;y<=n;y++)
{
if (a[x]<a[y])
{
b=a[x];
a[x]=a[y];
a[y]=b;
}
}
}
cout<<endl<<endl;
cout<<"Angka Setelah Diurutkan : "<<endl;
for(x=1;x<=n;x++)
{
cout<<a[x]<<" ";
}
cout<<endl<<endl;
}

Hasil Program
2. Program mengurutkan bilangan terbesar ke terkecil dengan iteratif
Flowchart
Start.

True
x=0 to n

a[x]

x++
False

x=0 to n
True

True
y=x to n

Ya
b=a[x]
a[x]<a[y] a[x]=a[y]
a[y]=b
Tidak

y++
False

x++
False
True
x=0 to n

a[x]

False
End.
x++
Program
#include<iostream>
using namespace std;
int main()
{
int a[100],n,x,y,b;
cout<<"==================================================="<<endl;
cout<<"| Program Mengurutkan Bilangan Terbesar ke Terkecil |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<"========================================="<<endl<<endl<<endl;
cout<<"Masukkan Banyaknya Angka : ";cin>>n;
cout<<endl<<endl;
for(x=1;x<=n;x++)
{
cout<<"Masukkan angka ke- "<<x<<" : "; cin>>a[x];
}
for(x=1;x<=n;x++)
{
for(y=x;y<=n;y++)
{
if (a[x]<a[y])
{
b=a[x];
a[x]=a[y];
a[y]=b;
}
}
}
cout<<endl<<endl;
cout<<"Angka Setelah Diurutkan : "<<endl;
for(x=1;x<=n;x++)
{
cout<<a[x]<<" ";
}
cout<<endl<<endl;
}

Hasil Program
3. Program mengurutkan bilangan terkecil ke terbesar dengan iteratif
Flowchart
Start.

True
x=0 to n

a[x]

x++
False

x=0 to n
True

True
y=x to n

Ya
b=a[x]
a[x]>a[y] a[x]=a[y]
a[y]=b
Tidak

y++
False

x++
False
True
x=0 to n

a[x]

False
End.
x++
Program
#include<iostream>
using namespace std;
int main()
{
int a[100],n,x,y,b;
cout<<"==================================================="<<endl;
cout<<"| Program Mengurutkan Bilangan Terbesar ke Terkecil |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<"========================================="<<endl<<endl<<endl;
cout<<"Masukkan Banyaknya Angka : ";cin>>n;
cout<<endl<<endl;
for(x=1;x<=n;x++)
{
cout<<"Masukkan angka ke- "<<x<<" : "; cin>>a[x];
}
for(x=1;x<=n;x++)
{
for(y=x;y<=n;y++)
{
if (a[x]>a[y])
{
b=a[x];
a[x]=a[y];
a[y]=b;
}
}
}
cout<<endl<<endl;
cout<<"Angka Setelah Diurutkan : "<<endl;
for(x=1;x<=n;x++)
{
cout<<a[x]<<" ";
}
cout<<endl<<endl;
}

Hasil Program
4. Program mengurutkan bilangan terbesar ke terkecil dengan rekursif
Program
#include<iostream>
int b[100];
void urutan(int bawah, int tengah, int atas)
{
int i,j,k,l, c[100];
i=bawah;
j=bawah;
k=tengah+1;
while((i<=tengah)&&(k<=atas))
{
if(b[i]>b[k])
{
c[j]=b[i];
i++;
}
else
{
c[j]=b[k];
k++;
}
j++;
}
if(i>tengah)
{
for(l=k;l<=atas;l++)
{
c[j]=b[l];
j++;
}
}
else
{
for(l=i;l<=tengah;l++)
{
c[j]=b[l];
j++;
}
}
for(l=bawah;l<=atas;l++)
{
b[l]=c[l];
i++;
}
}
void urutans (int bawah, int atas)
{
int tengah;
if(bawah<atas)
{
tengah=(bawah+atas)/2;
urutans(bawah,tengah);
urutans(tengah+1,atas);
urutan(bawah,tengah,atas);
}
}
using namespace std;

int main()
{
int jum,i;
cout<<"======================================================="<
<endl;
cout<<"| Program Mengurutkan Bilangan Terkecil ke Terbesar |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<"======================================================="<
<endl<<endl<<endl;
cout<<"Masukkan Jumlah Bilangan : ";cin>>jum;
for(i=1;i<=jum;i++)
{
cout<<"Masukkan Bilangan ke "<<i<<" : ";
cin>>b[i];
}
urutans(1,jum);
cout<<"Bilangan Setelah Dirutkan : ";
for(i=1;i<=jum;i++)
{
cout<<b[i]<<" ";
}
cout<<endl<<endl;
return 0;
}

Hasil Program
5. Program mengurutkan bilangan terkecil ke terbesar dengan rekursif
Program
#include<iostream>
int b[100];
void urutan(int bawah, int tengah, int atas)
{
int i,j,k,l, c[100];
i=bawah;
j=bawah;
k=tengah+1;
while((i<=tengah)&&(k<=atas))
{
if(b[i]<b[k])
{
c[j]=b[i];
i++;
}
else
{
c[j]=b[k];
k++;
}
j++;
}
if(i>tengah)
{
for(l=k;l<=atas;l++)
{
c[j]=b[l];
j++;
}
}
else
{
for(l=i;l<=tengah;l++)
{
c[j]=b[l];
j++;
}
}
for(l=bawah;l<=atas;l++)
{
b[l]=c[l];
i++;
}
}
void urutans (int bawah, int atas)
{
int tengah;
if(bawah<atas)
{
tengah=(bawah+atas)/2;
urutans(bawah,tengah);
urutans(tengah+1,atas);
urutan(bawah,tengah,atas);
}
}
using namespace std;

int main()
{
int jum,i;
cout<<"======================================================="<
<endl;
cout<<"| Program Mengurutkan Bilangan Terkecil ke Terbesar |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<"======================================================="<
<endl<<endl<<endl;
cout<<"Masukkan Jumlah Bilangan : ";cin>>jum;
for(i=1;i<=jum;i++)
{
cout<<"Masukkan Bilangan ke "<<i<<" : ";
cin>>b[i];
}
urutans(1,jum);
cout<<"Bilangan Setelah Dirutkan : ";
for(i=1;i<=jum;i++)
{
cout<<b[i]<<" ";
}
cout<<endl<<endl;
return 0;
}

Hasil Program

You might also like