Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

LAPORAN ALGORITMA 1. Foto kopi: Bahasa Pemrograman #include <stdio.h> #include <conio.

.h> void main(){ clrscr(); printf("Lembar\tHarga\n"); printf("-------------\n"); for(int i=1;i<=100;i++){ printf("%d\t%d\n",i,(i*80)); } getch(); } Hasil :

flowchart

START

i=1

t
i <= 100

y
hrg = i * 80 ; i=i +1

i, hrg

2. Bilangan 1 sampai 20: END Bahasa Pemrograman #include <stdio.h> #include <conio.h> void main(){ int i,j; for(i=1;i<=20;i++){ if(i % 5 == 0) printf("%d\n",i); else printf("%d\t",i); }

Hasil:

Flowchart

START

i, t

t=1 ; i=1

i=20

If i=t*5 Y I enter

TDK

t=t+1

3. Tabel P dan Q

Bahasa Pemrograman #include <stdio.h> #include <conio.h> void main(){ int i,j; printf("P\tQ\tP or Q\tP and Q\tNot P\tP xor Q\tP Nand Q\n");

FINISH

printf("===================================================== ======\n"); for(i=1;i>=0;i--){ for(j=1;j>=0;j--){ printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,j,(i || j),(i && j),!i,(i ^ j),(!(i && j)) ); } } }

Hasil:

Flowchart

S T AR T

i=1

i <= 4

y t y
i=2 p=1; q=1

i=1

t y
i=3

t y

p=1; q=0

p=0; q=1 p=0; q=0

p, q

4. Bilangan fibonacci

EN D

Bahasa Pemrograman #include<stdio.h> #include<conio.h> #include<iostream.h> #include<math.h> void main() {

clrscr(); long a,b=1,c=0,hasil,input; cout<<"Masukkan Bilangan:"; cin>>input; for(a=1;a<+input;a++) { hasil=b+c; cout<<hasil; b=c; c=hasil; } getch(); }

Hasil

Flowchart
START

inp

x=0;y =1; i=1

i <= inp

tdk

y
y

z=x +y;x= y;y=z

END

5. FBP Bahasa pemorgraman #include<iostream.h> #include<conio.h>

int main() {

int m,n,r; cout<<"masukan nilai A :"; cin>>m; cout<<"masukan nilai B:"; cin>> n; r=m%n; while (r!=0) { m=n; n=r; r=m%n; } cout<<"faktor persekutuan terbesar dari A dan B adalah:"<<n<<endl; getch(); } Hasil:

Flowchart
strat

m, n, r

r,m,n=0

r=m%n

fpb

finish

6. Jumlah bilangan genap ganjil Bahasa pemrograman #include<stdio.h> #include<stdlib.h> #include<iostream.h> #include<conio.h>

void main(){

clrscr(); int i, ak, aw, totgen, totgan; cout<<"Masukkan Batas Awal : "; cin>>aw; ak = 0; while(aw>ak){ cout<<"Masukkan Batas Akhir : "; cin>>ak; } totgen = 0; totgan = 0; for (i= aw;i<=ak;i++){ if (i%2==0){ totgen = totgen + i; }else{ totgan = totgan + i; } } cout<<"Total Genap : "<<totgen<<endl; cout<<"Total Ganjil : " <<totgan<<endl; getch(); }

Hasil:

Flowchart

START

awal, akhir

t
awal < akhir

Y
totGen = 0 ; totGan = 0 ; i = awal

i <= akhir

y t
i %2=0

y
totGen = totGen + 1

totGan = totGan + 1

i=i +1

totGen, totGan

END

You might also like