Program Segitiga Pascal (Pake Fungsi) C++

November 18, 2017


Script program (dengan Borland C++):

#include <iostream.h>
#include <conio.h>

int fact (int n);
int ncr (int n, int r);
void main ()
{
cout<<endl;
cout<<"SEGITIGA PASCAL"<<endl;
cout<<endl;
int n;
   cout<<"Masukkan baris: ";
   cin>>n;
   cout<<endl;

   int i, j, k;

   for (i=0;i<n;i++)
   {
   for (j=n-i;j>0;j--)
{ cout<<" ";
   }
   for (k=0;k<=i;k++)
   {cout<<" "<<ncr(i,k);
   }
   cout<<"\n";
   }
   getch ();
   }

int fact (int n)
{
if (n==1||n==0)
   {
    return 1;
   }
    return n*fact(n-1);
}
int ncr (int n, int r)
{
return fact(n)/(fact(r)*fact(n-r));
}

You Might Also Like

0 komentar