Advertisement
oimtrust

looping.cpp

Oct 31st, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.    //Perulangan for
  9.    int angka,pil;
  10.    cout<<"Masukkan angka ";
  11.    cin>>angka;
  12.    cout<<"Pilihan\n1.Ganjil\n2.Genap" <<endl;
  13.    cout<< "masukkan pilihan ";
  14.    cin>>pil;
  15.         switch(pil){
  16.             case 1:
  17.                 for(int i=1; i<=angka; i++){
  18.                   if(i%2==1){
  19.                    cout<< i <<endl;
  20.                   }
  21.                 }
  22.             break;
  23.             case 2:
  24.                 for(int i=1; i<=angka; i++){
  25.                   if(i%2==0){
  26.                    cout << i << endl;
  27.                   }
  28.                 }
  29.             break;
  30.             default:cout<<"pilihan salah";
  31.         }
  32.  
  33.     }
  34.  
  35.  
  36.  
  37. /*
  38. int main()
  39. {
  40.     float total = 0;
  41.  
  42.     for(int count = 0; count < 4; count++)  // Perulangan dilakukan sebanyak 4 kali
  43.     {
  44.         int num = 0;
  45.         std::cout << "enter a number" << std::endl;
  46.         std::cin >> num;
  47.         total += num;
  48.     }
  49.     std::cout << "the sum is " << total << std::endl; // " menghitung jumlah inputan angka
  50. }
  51. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement