Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1.

Membuat program Pascal iteratif


Flowchart Start.

batas

True
i=0 to
batas

True j=0 to
(2*batas)-(2*i)

""

j++

False
True
k=0 to i

Ya
k==0||i==k a=1

Tidak

a=a*(i+1-k)/k

" ",a," "

False
k++
i++

False
"" End.
Program
#include<iostream>
using namespace std;
int main()
{
int batas,a,i,k,j;
cout<<" ====================================== "<<endl;
cout<<"| Program Membuat Pascal |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<" ====================================== "<<endl<<endl<<endl;
cout<<"Masukkan batas : ";cin>>batas;
cout<<endl<<endl;
for(i=0;i<=batas;i++)
{
for(j=0;j<=((2*batas)-(2*i));j++){
cout<<" "; }
for(k=0;k<=i;k++)
{
if(k==0||i==k)
{
a=1;
}
else
{
a=a*(i+1-k)/k;
}
cout<<" ";
cout<<a;
cout<<" ";
}
cout<<" ";
cout<<endl<<endl;
}
cout<<endl<<endl<<endl;
}
Hasil Program
2. Buatlah Program menentukan huruf yang dominan pada suatu kata.
Flowchart Start.

Start.

batas
Ya
spasi=batas
kolom==0|| return 1
True kolom==baris
i=0 to batas
Tidak
True
return Pascal(baris-1,
j=0 to spasi
kolom)+Pascal(baris-
1,kolom-1);
""

End.

j++

False
True
j=0 to i

" "<<Pascal(i,j)" "

spasi--

j++

False

i++

False

End.
Program
#include<iostream>
#include<conio.h>
#include<stdio.h>
int Pascal(int baris, int kolom)
{
if (kolom==0||kolom==baris)
return 1;
else
return Pascal(baris-1,kolom)+Pascal(baris-1,kolom-1);
}
using namespace std;
int main()
{
int batas,spasi,i,j;
cout<<" ======================================= "<<endl;
cout<<"| Program Membuat Pascal Rekursif |"<<endl;
cout<<"| Oleh : Fahira Anggraini |"<<endl;
cout<<" ======================================= "<<endl<<endl<<endl;
cout<<"Masukkan Tinggi : ";cin>>batas;
cout<<endl<<endl;
spasi=batas;
for(i=0;i<=batas;i++){
for(j=0;j<=spasi;j++)
cout<<" ";
for(j=0;j<=i;j++)
cout<<" "<<Pascal(i,j)<<" ";
cout<<" "<<endl<<endl;
spasi--;
cout<<endl<<endl; }
}

Hasil Progarm
3. Program Menentukan Huruf Dominan
Program
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char kata[100],hrf;
int maks,h,t,i,j,ha,hb,hc,hd,he,hf,hg,hh,hi,hj,hk,hl,hm,hn,ho,hp,hq,hr,hs,ht,hu,hv,hw,
hx,hy,hz,N,huruf[50];
t=0;
ha=0;hb=0;hc=0;hd=0;he=0;hf=0;hg=0;hh=0;hi=0;hj=0;hk=0;hl=0;hm=0;
hn=0;ho=0;hp=0;hq=0;hr=0;hs=0;ht=0;hu=0;hv=0;hw=0;hx=0;hy=0;hz=0;
cout<<"=========================================="<<endl;
cout<<" Program Menentukan Huruf Terbanyak Dari Suatu Kata "<<endl;
cout<<" Oleh : Fahira Anggraini "<<endl;
cout<<"========================================"<<endl<<endl<<endl;
cout<<"Masukkan kata : ";cin>>kata;
h=strlen(kata);
for(i=0;i<h;i++)
{
if(kata[i]=='a'||kata[i]=='A')
ha=ha+1;
else if(kata[i]=='b'||kata[i]=='B')
hb=hb+1;
else if(kata[i]=='c'||kata[i]=='C')
hc=hc+1;
else if(kata[i]=='d'||kata[i]=='D')
hd=hd+1;
else if(kata[i]=='e'||kata[i]=='E')
he=he+1;
else if(kata[i]=='f'||kata[i]=='F')
hf=hf+1;
else if(kata[i]=='g'||kata[i]=='G')
hg=hg+1;
else if(kata[i]=='h'||kata[i]=='H')
hh=hh+1;
else if(kata[i]=='i'||kata[i]=='I')
hi=hi+1;
else if(kata[i]=='j'||kata[i]=='J')
hj=hj+1;
else if(kata[i]=='k'||kata[i]=='K')
hk=hk+1;
else if(kata[i]=='l'||kata[i]=='L')
hl=hl+1;
else if(kata[i]=='m'||kata[i]=='m')
hm=hm+1;
else if(kata[i]=='n'||kata[i]=='n')
hn=hn+1;
else if(kata[i]=='o'||kata[i]=='O')
ho=ho+1;
else if(kata[i]=='p'||kata[i]=='P')
hp=hp+1;
else if(kata[i]=='q'||kata[i]=='Q')
hq=hq+1;
else if(kata[i]=='r'||kata[i]=='R')
hr=hr+1;
else if(kata[i]=='s'||kata[i]=='S')
hs=hs+1;
else if(kata[i]=='t'||kata[i]=='T')
ht=ht+1;
else if(kata[i]=='u'||kata[i]=='U')
hu=hu+1;
else if(kata[i]=='v'||kata[i]=='V')
hv=hv+1;
else if(kata[i]=='w'||kata[i]=='W')
hw=hw+1;
else if(kata[i]=='x'||kata[i]=='X')
hx=hx+1;
else if(kata[i]=='y'||kata[i]=='Y')
hy=hy+1;
else if(kata[i]=='z'||kata[i]=='Z')
hz=hz+1;
}
huruf[0]=ha;huruf[1]=hb;huruf[2]=hc;huruf[3]=hd;huruf[4]=he;huruf[5]=hf;
huruf[6]=hg;huruf[7]=hh;huruf[8]=hi;huruf[9]=hj;huruf[10]=hk;huruf[11]=hl;
huruf[12]=hm;huruf[13]=hn;huruf[14]=ho;huruf[15]=hp;huruf[16]=hq;huruf[17]=hr;
huruf[18]=hs;huruf[19]=ht;huruf[20]=hu;huruf[21]=hv;huruf[22]=hw;huruf[23]=hx;
huruf[24]=hy;huruf[25]=hz;
maks=huruf[0];
for(j=1;j<26;j++){
if(huruf[j]>maks){
maks=huruf[j];} }
for(j=0;j<26;j++){
if(huruf[j]==maks)
t=t+1;}
if (ha==maks)
hrf='a';
if (hb==maks)
hrf='b';
if (hc==maks)
hrf='c';
if (hd==maks)
hrf='d';
if (he==maks)
hrf='e';
if (hf==maks)
hrf='f';
if (hg==maks)
hrf='g';
if (hh==maks)
hrf='h';
if (hi==maks)
hrf='i';
if (hj==maks)
hrf='j';
if (hk==maks)
hrf='k';
if (hl==maks)
hrf='l';
if (hm==maks)
hrf='m';
if (hn==maks)
hrf='n';
if (ho==maks)
hrf='o';
if (hp==maks)
hrf='p';
if (hq==maks)
hrf='q';
if (hr==maks)
hrf='r';
if (hs==maks)
hrf='s';
if (ht==maks)
hrf='t';
if (hu==maks)
hrf='u';
if (hv==maks)
hrf='v';
if (hw==maks)
hrf='w';
if (hx==maks)
hrf='x';
if (hy==maks)
hrf='y';
if (hz==maks)
hrf='z';
cout<<endl<<endl;
if(t>1)
{
cout<<"Tidak Ada Huruf Dominan"<<endl;
}
else
{
cout<<"Huruf dominannya adalah "<<hrf<<endl;
cout<<"Dengan Jumlah : "<<maks;
}
cout<<endl;
}
Hasil Program

You might also like