Pattern 27 (Pascal Triangle)

Pattern 27 (Pascal Triangle)
  • C Code
  • C++ Code
  • Java Code
  • Get these codes on your Android Device

C Code


        1
       1 1
      1 2 1
     1 3 3 1
    1 4 6 4 1 
#include<stdio.h> long fact(int); int main(){ int line_no,i,j; printf("Enter the no. of lines: "); scanf("%d",&line_no); for(i=0;i<line_no;i++){ for(j=0;j<line_no-i-1;j++) { printf(" "); } for(j=0;j<=i;j++) { printf("%ld ",fact(i)/(fact(j)*fact(i-j))); } printf("n"); } return 0; } long fact(int num){ long f=1; int i=1; while(i<=num){ f=f*i; i++; } return f; }

C++ Code


        1
       1 1
      1 2 1
     1 3 3 1
    1 4 6 4 1 
#include<iostream.h> long fact(int); int main(){ int line_no,i,j; cout<<"Enter the no. of lines: "; cin>>line_no; for(i=0;i<line_no;i++){ for(j=0;j<line_no-i-1;j++) { cout<<" "; } for(j=0;j<=i;j++) { cout<<fact(i)/(fact(j)*fact(i-j))<<" "; } cout<<endl; } return 0; } long fact(int num){ long f=1; int i=1; while(i<=num){ f=f*i; i++; } return f; }

Java Code


        1
       1 1
      1 2 1
     1 3 3 1
    1 4 6 4 1 
class Pascal_Triangle_Pattern27 { public static void main(String args[]) { int i,j,line_no=5; for(i=0;i<line_no;i++) { for( j=0;j<line_no-i-1;j++) { System.out.print(" "); } for( j=0;j<=i;j++) { System.out.print(fact(i)/(fact(j)*fact(i-j))+" "); } System.out.println(); } } //end of main static long fact(int num){ long f=1; int i=1; while(i<=num){ f=f*i; i++; } return f; }

Android Apps


Get pattern printing codes on your Android Device :

# C Pattern Programs Free App
# C++ Pattern Programs Free App
# Java Pattern Programs Free App


Get Them Now !!!

Download Code           More Patterns !!!