Thursday, November 29, 2012

Penggunaan While, Do while, For

Alhamdullilah tugas 6 tentang pengulangan menggunakan while, do while dan for dapat terselesaikan... scriptnya sbb :

#include <iostream>
using namespace std; //

int main()
{
  int x = 0;  // Deklarasi
 
  cout<<"==========While================";
  while ( x < 10 ) { // While x is less than 10
    cout<< x <<endl;
    x++;             // Update x so the condition can be met eventually
  }
  cout<<"===============================";
  cout<<"\n";

 cout<<"=========Do while===============";
  int A;

  A = 0;
  do {
    // "Hello, world!" akan dicetak 1x dulu
       cout<<"Hello, world!"<<endl;
         
  } while ( A != 0 );// akan melakukan perulangan tak terbatas jika nilai A tidak 0
  cout<<"===============================";
  cout<<"\n";
 
 cout<<"========= Do while ===============";
long pass, input ;
pass=12345;
do{
    cout<<"masukan password yg benar; ";
    cin>>input;
}while (input!=pass);
cout<<"password benar\n";
cout<<"terima kasih telah mencoba program ini......."<<endl;
cout<<"==============================================";
cout<<"\n";

cout<<"========= For ===============";
int C,D;
cout << "PENGULANGAN MENAIK" << endl;
for (C=0; C<4; C++) {
       cout << C+1 << endl;
 }
cout << '\n';

cout << "PENGULANGAN MENURUN" << endl;
 for (D=4; D>0; D--)
 {
 cout << D << endl;
 }
 cout<<"==============================";
 cout<<"\n";

cout<<"========= For Bersarang ===============";
 for (int j=1; j<=4; j++) {;
       for (int k=1; k<=j; k++) {;
       cout << k*j <<' ';
       }

 cout << '\n';
 }
cout<<"==============================";

 system("pause");
return 0;

}

Sedangkan vidio tutorialnya :
 





No comments:

Post a Comment