[ create a new paste ] login | about

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

C, pasted on Jun 8:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100

// Hợp lệ: Trả về 1, không hợp lệ: Trả về 0
int KiemTraSoNguyen(char *x)
{
	int Check = 1; // Khởi tạo
	fflush(stdin);

	// Kiểm tra chuỗi hợp lệ
	int length = strlen(x);
	
	for(int i = 0; i < length; i++)
	{
		if(x[i] < '0' || x[i] > '9')
		{
			Check = 0;
			break;
		}
	}
	return Check;
}
void NhapMang(int a[][MAX], int dong, int cot)
{
	for(int i = 0; i < dong; i++)
	{
		for(int j = 0; j < cot; j++)
		{
			printf("\nNhap vao a[%d][%d] = ", i, j);
			scanf("%d", &a[i][j]);
		}
	}
}
void XuatMang(int a[][MAX], int dong, int cot)
{
	for(int i = 0; i < dong; i++)
	{
		for(int j = 0; j < cot; j++)
		{
			printf("\%4d", a[i][j]);
		}
		printf("\n\n");
	}
}
void HoanVi2So(int &a, int &b)
{
	a = a + b; // a = a + b
	b = a - b; // b = a
	a = a - b; // a = b
}
void HoanVi2Dong(int a[][MAX], int x, int y, int cot)
{
	for(int i = 0; i < cot; i++)
	{
		HoanVi2So(a[x][i],a[y][i]);
	}
}
void XoaDong(int a[][MAX], int &dong, int cot, int vitrixoa)
{
	for(int i = vitrixoa + 1; i < dong; i++)
	{
		HoanVi2Dong(a,i - 1, i,cot);
	}
	dong--;
}
int main()
{
	// int a[2][3] = {{1,2,3}, {4, 5, 6}};
  //  XuatMang(a,2,3);

	int a[MAX][MAX], dong, cot;

	// Nhập số dòng
	char sodong[30];
	int CheckDong;
	do{
	fflush(stdin);
	printf("\nNhap vao so dong: ");
	gets(sodong);

	 CheckDong = KiemTraSoNguyen(sodong);

	if(CheckDong == 0)
	{
		printf("\nKieu du lieu khong hop le. Xin kiem tra lai !");
	}
	else
	{
		dong = atoi(sodong);
		if(dong < 1 || dong > MAX)
		{
			CheckDong = 0;
			printf("\nSo dong khong hop le. Xin kiem tra lai !");
		}
	}
	}while(CheckDong == 0);
	// Nhập số cột
	do
	{
		printf("\nNhap vao so cot: ");
		scanf("%d", &cot);

		if(cot < 1 || cot > MAX)
		{
			printf("\nSo cot khong hop le. Xin kiem tra lai !");
		}
	}while(cot < 1 || cot > MAX);

	NhapMang(a,dong,cot);
	XuatMang(a,dong,cot);

	/*HoanVi2Dong(a,0,1,cot);
	printf("\nMa tran sau khi hoan vi 2 dong 0 va 1\n");
	XuatMang(a,dong,cot);*/

	/*XoaDong(a,dong,cot,0);
	printf("\nMa tran sau khi xoa dong %d \n",0);
	XuatMang(a,dong,cot);*/

	int vitridongcanxoa;
	do{
		printf("\nNhap vao vi tri dong can xoa: ");
		scanf("%d", &vitridongcanxoa);

		if(vitridongcanxoa < 0 || vitridongcanxoa > dong - 1)
		{
			printf("\nVi tri xoa khong hop le. Xin kiem tra lai !");
		}
	}while(vitridongcanxoa < 0 || vitridongcanxoa > dong - 1);

	XoaDong(a,dong,cot,vitridongcanxoa);
	XuatMang(a,dong,cot);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Line 17: error: conio.h: No such file or directory
In function 'KiemTraSoNguyen':
Line 16: error: 'for' loop initial declaration used outside C99 mode
In function 'NhapMang':
Line 28: error: 'for' loop initial declaration used outside C99 mode
Line 30: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMang':
Line 39: error: 'for' loop initial declaration used outside C99 mode
Line 41: error: 'for' loop initial declaration used outside C99 mode
t.c: At top level:
Line 48: error: expected ';', ',' or ')' before '&' token
In function 'HoanVi2Dong':
Line 56: error: 'for' loop initial declaration used outside C99 mode
t.c: At top level:
Line 61: error: expected ';', ',' or ')' before '&' token


Create a new paste based on this one


Comments: