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.0074 sec