Advertisement
ZulRocky

Piramida Pascal C++

Jan 29th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. // SILAHKAN COMOT GANN
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int baris, koef = 1;
  8.  
  9.     cout << "Masukan banyak baris: ";
  10.     cin >> baris;
  11.  
  12.     for(int i = 0; i < baris; i++)
  13.     {
  14.         for(int spasi = 1; spasi <= baris-i; spasi++){
  15.             cout <<"  ";
  16.         }
  17.         for(int j = 0; j <= i; j++)
  18.         {
  19.             if (j == 0 || i == 0){
  20.                 koef = 1;
  21.             }
  22.             else{
  23.                 koef = koef*(i-j+1)/j;
  24.             }
  25.             cout << koef << "   ";
  26.         }
  27.         cout << endl;
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement