[ create a new paste ] login | about

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

C, pasted on Jun 20:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void NhapMang(int *a, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("\nNhap vao a[%d] = ", i);
		//scanf("%d", &a[i]);
		//scanf("%d", a + i);
		scanf("%d", a++);
	}
}

void XuatMang(int *a, int n)
{
	for (int i = 0; i < n; i++)
	{
		//printf("%4d",a[i]);
		//printf("%4d", *(a + i));
		printf("%4d", *(a++));
	}
}

int main()
{
	int n;
	do 
	{
		printf("\nNhap vao so luong phan tu cua mang: ");
		scanf("%d", &n);

		if (n < 0)
		{
			printf("\nSo luong phan tu khong hop le. Xin kiem tra lai !");
		}
	} while (n < 0);

	// Cấp phát
	int *a;
	//a = (int *)malloc(n * sizeof(int));
	a = (int *)calloc(n, sizeof(int));
	//a = (int *)realloc(0, n * sizeof(int));


	NhapMang(a,n);
	XuatMang(a,n);

	//realloc(a, (n - 1) * sizeof(int));

	//a[n] = 69;
	//printf("\n\na[%d] = %d",n, a[n]);  
	printf("\na[%d] = %d", n - 1, a[n - 1]);
	free(a);  // Giải phóng

	getch();
	return 0;
}


Output:
1
2
3
4
5
Line 17: error: conio.h: No such file or directory
In function 'NhapMang':
Line 6: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMang':
Line 17: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: