#include <stdio.h>
// Calculate Pascal Triangel with two one dementional arrays
#define LineNum 7
void main(){
    int  arr1[LineNum+1] , arr2[LineNum+1] , i=1 , j=1 ;
    arr1[0]=arr2[0]=0;
    arr1[1]=1;
    if (LineNum==1) printf("   1 \n");
    if (LineNum>1)	{
      for (i=1 ; i<=LineNum ; i++) {
	arr2[i]=1;
	for (j=1 ; j<i ; j++) arr2[j] = arr1[j-1]+arr1[j];
	for (j=1;j<=i;j++){
		printf("%4d ",arr2[j]);
		arr1[j] = arr2[j] ;
	}
	printf("\n");
      }
    }
}
Published in: C++
Download

Related snippets