How To Print "HAPPY" In A Triangle In C++?

C language program to print pascal triangle with explanation?

  • Answer:

    #include<Stdio.h> #include<conio.h> void main() { int a[20][20],i,j,n,spc=25,k; printf("\n enter the number of lines:"); scanf("%d",&n); for(i=0;i<n;i++) //outer loop for rows { for(k=spc-2*i;k>=0;k--) printf(" "); //to print spaces for(j=0;j<=i;j++) //inner loop for colums { if(j==0||i==j) { a[i][j]=1; } else { a[i][j]=a[i-1][j-1]+a[i-1][j]; } printf("%4d",a[i][j]); } printf("\n"); } getch(); } The above program demonstrate pascal triangle using 2D array by normal looping. #include<stdio.h> main() { int i,j,k; clrscr(); printf("\n") ; for(i=1 ;i<= 10 ;i++ ) { for(j=1 ;j<= 31-i;j++)printf(" ") ; for(j=i,k=(2 *i -1)/2+1 ;k;j++,k-- ) { if(j==10)j=0 ; printf("%d",j) ; } for(j-=2,k=(2 *i -1)/2 ;k;j--,k-- ) { if(j==-1)j=9 ; printf("%d",j) ; } printf("\n") ; } getch(); }

community wiki at wiki.answers.com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.