U E D R , A S I H C RSS

파스칼삼각형/강희경

바보
른 문.
.
#include <iostream>
using namespace std;

void printArray(int *arr, int n);  //  
void copyArray(int *fArr, int *arr);  //  

int column;

int main(){
	cout << "    (ex,6).";
	cin >> column;
	if(column > 0){
		int *array = new int[column];  // 
		int *foreArray = new int[column];  //()  
		for(int i = 0; i<column; i++){
			array[0] = 1;  //   1
			for(int j = 1; j < column-1; j++){  // 머리  는 2 를 더 
				array[j] = foreArray[j-1] + foreArray[j];
			}
			array[i] = 1;  //   1
			printArray(array, i);  // .
			copyArray(foreArray, array);  //     .
		}
	}
	else
		cout << " ."<< endl;
	return 0;
}

void printArray(int *arr, int n){
	int blank = (column - n)/2;
	for(int j = 0;j < blank; j++){  //  
		cout << " ";
	}
	for(int i = 0; i <= n; i++){   //   
		cout << arr[i] << " ";
	}
	cout << endl;
}

void copyArray(int *fArr, int *arr){
	for(int i = 0; i < column; i++){
		fArr[i] = arr[i];
		arr[i] = 0;
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:22
Processing time 0.0073 sec