1 / 11

Kondisi dan Perulangan pada C++

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;

lynnea
Download Presentation

Kondisi dan Perulangan pada C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Kondisi dan Perulangan pada C++ Teknik Pemrograman Terstruktur 2

  2. Kondisi • Struktur Program • If (kondisi) • Statement 1; • Else • Statement 2;

  3. 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(); • }

  4. SELECT CASE • Struktur Program : • switch (kondisi) • { • case 1 : • statement 1; • break; • case 2 : • Statement 2; • break; • default : • statement; • }

  5. Contoh pemrograman select case

  6. Perulangan • Struktur program : • while (perulangan) • { • Statement; • } • For (perulangan) • { • Statement; • }

  7. 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();

  8. Perulangan for long 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; }

More Related