[ create a new paste ] login | about

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

C, pasted on Apr 26:
#include<stdio.h>
#include<conio.h>
#define MAX 100

void NhapMang(int a[], int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("\nNhap vao phan tu a[%d] = ", i);
		scanf_s("%d", &a[i]);
	}
}
void XuatMang(int a[], int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%4d", a[i]);
	}
}

void XoaPhanTu(int a[], int &n, int ViTriXoa)
{
	for (int i = ViTriXoa; i < n - 1; i++)
	{
		a[i] = a[i + 1];
	}
	n--;
}

void XoaPhanTuSoChan(int a[], int &n)
{
	for (int i = 0; i < n; i++)
	{ 
	   if (a[i] % 2 == 0)
	   {
		   XoaPhanTu(a, n, i);
		   i--; // Lùi lại để xét lại từ vị trí hiện tại
	   }
	}
}
int main()
{
	int n;

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

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

	int a[MAX];
	NhapMang(a, n);
	XuatMang(a, n);

	//int ViTriXoa;

	//// 0 <= ViTriXoa < n
	//do
	//{
	//	printf("\nNhap vao vi tri xoa (%d --> %d) ",0,n);
	//	scanf_s("%d", &ViTriXoa);

	//	if (ViTriXoa < 0 || ViTriXoa >= n)
	//	{
	//		printf("\nVi tri xoa khong hop le. Xin kiem tra lai !");
	//	}
	//} while (ViTriXoa < 0 || ViTriXoa >= n);

	//XoaPhanTu(a, n, ViTriXoa);
	//printf("\nMang sau khi xoa phan tu tai vi tri %d la: \n", ViTriXoa);
	//XuatMang(a,n);


	XoaPhanTuSoChan(a, n);
	printf("\nMang sau khi xoa tat ca cac phan tu so chan la: \n");
	XuatMang(a, n);
	_getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
Line 17: error: conio.h: No such file or directory
In function 'NhapMang':
Line 7: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMang':
Line 15: error: 'for' loop initial declaration used outside C99 mode
t.c: At top level:
Line 21: error: expected ';', ',' or ')' before '&' token
Line 30: error: expected ';', ',' or ')' before '&' token


Create a new paste based on this one


Comments: