U E D R , A S I H C RSS

데블스캠프2006/화요일/pointer/문제3/성우용

1번
~cpp
#include<iostream>
using namespace std;

void main()
{
	int i;
	int *a = new int[4];
	int *b = new int[4];
	int *c = new int[4];

	for(i=0;i<4;i++)
		a[i] = i;
	
	for(i=0;i<4;i++)
		b[i] = 4-i;

	for(i=0;i<4;i++)
		c[i] = a[i] + b[i];
	
	for(i=0;i<4;i++)
	cout << c[i];
	
	delete []a;
	delete []b;
	delete []c;
}

2번
~cpp
#include<iostream>
using namespace std;

void main()
{
	int i,j;
	int **a = new int*[5];
	int **b = new int*[5];
	int **c = new int*[5];
	int **d = new int*[5];

	for(i=0;i<5;i++)
		a[i] = new int[5]; 
	for(i=0;i<5;i++)
		c[i] = new int[5]; 
	for(i=0;i<5;i++)
		b[i] = new int[5]; 

	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			a[i][j] = i * j;
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			cout<<a[i][j];
			cout<<"  ";
		}
		cout<<"\n";
	}
	cout<<"\n";
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			b[i][j] = i + j;
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			cout<<b[i][j];
			cout<<"  ";
		}
		cout<<"\n";
	}
	cout<<"\n";
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			c[i][j] = a[i][j] + b[i][j];
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			cout<<c[i][j];
			cout<<"  ";
		}
		cout<<"\n";
	}
	cout<<"\n";
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			c[i][j] = a[i][j] - b[i][j];
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			cout<<c[i][j];
			cout<<"  ";
		}
		cout<<"\n";
	}
	cout<<"\n";
	
	delete []a;
	delete []b;
	delete []c;
	delete []d;
}

----
데블스캠프2006/화요일/pointer
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.5961 sec