[ create a new paste ] login | about

Link: http://codepad.org/xWx2qKJ0    [ raw code | output | fork ]

C, pasted on Jan 6:
#include<iostream>
using namespace std;

//a + i <=> &a[0 + i] ;

//*(a+i) <=> a[i]

void NhapMang(int* a, int n)
{
	for(int i = 0; i < n; i++)
	{
		cout << "Nhap a[" << i << "]: \n";
		cin >> *(a + i);
	}
}

void XuatMang(int* a, int n)
{
	for(int i = 0; i < n; i++)
	{
		cout << *(a + i) << " ";
	}
}

int main()
{
	int *a = NULL;
	int n = 0;
	do{
		cout << "Nhap so luong phan tu:\n";
		cin >> n;
		if(n < 0)
			cout << "So luong la phai >= 0!\n";
	}while(n < 0);
	a = new int[n];	// Xin cấp phát n ô nhớ kiểu int ở vùng nhớ HEAP
	NhapMang(a, n);
	XuatMang(a, n);
	if(a != NULL)
	{
		delete[] a;	// Thu hồi n ô nhớ vừa xin cấp phát trước đó 
	}

	system("pause");
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Line 18: error: iostream: No such file or directory
Line 2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
In function 'NhapMang':
Line 10: error: 'for' loop initial declaration used outside C99 mode
Line 12: error: 'cout' undeclared (first use in this function)
Line 12: error: (Each undeclared identifier is reported only once
Line 12: error: for each function it appears in.)
Line 13: error: 'cin' undeclared (first use in this function)
In function 'XuatMang':
Line 19: error: 'for' loop initial declaration used outside C99 mode
Line 21: error: 'cout' undeclared (first use in this function)
In function 'main':
Line 30: error: 'cout' undeclared (first use in this function)
Line 31: error: 'cin' undeclared (first use in this function)
Line 35: error: 'new' undeclared (first use in this function)
Line 35: error: expected ';' before 'int'
Line 40: error: 'delete' undeclared (first use in this function)
Line 40: error: expected expression before ']' token


Create a new paste based on this one


Comments: