Kondisi dan Perulangan pada C++

Post on 04-Jan-2016

176 Views

Category:

Documents

8 Downloads

Preview:

Click to see full reader

DESCRIPTION

Kondisi dan Perulangan pada C++. Teknik Pemrograman Terstruktur 2. Kondisi. Struktur Program If (kondisi) Statement 1; Else Statement 2;. Contoh program kondisi. #include #include #include main() { clrscr(); int bilangan; - PowerPoint PPT Presentation

Transcript

Kondisi dan Perulangan pada C++TEKNIK PEMROGRAMAN TERSTRUKTUR 2

Kondisi Struktur Program

If (kondisi)

Statement 1;

Else

Statement 2;

Contoh program kondisi

#include <stdio> #include <conio> #include <iostream> main() { clrscr(); int bilangan; cout<<“masukan sebuah bilangan = “; cin>>bilangan; if (bilangan %2 == 0) cout<<“bilangan genap”; else cout<<“bilangan ganjil; getch(); }

SELECT CASE Struktur Program :

switch (kondisi) { case 1 : statement 1; break; case 2 : Statement 2; break; default : statement; }

Contoh pemrograman select case

Perulangan Struktur program : while (perulangan) { Statement; }

For (perulangan) { Statement; }

Contoh program perulangan

Int x, y, z; Cout<<“masukan nilai x = “; Cin>>x; Cout<<“masukan nilai y = “; Cin>>y; z = x % y; While(z !=0) { X = y; Y = z; Z = x%y; } Cout<<“Faktor Persekutuan Besar = “<<y; Getch();

Perulangan forlong int pokok, bunga;int tahun;cout<<“masukan gaji pokok = “;cin>>pokok;for (tahun = 1; tahun <=8; tahun++){bunga = (pokok*7)/100;cout<<setw(2)<<tahun<<endl<<setw(9)<<pokok<<setw(9)<<bunga<<endl;pokok = pokok + bunga;}

top related