[ create a new paste ] login | about

Link: http://codepad.org/m1wuf6xu    [ 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");
	}
}
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);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
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


Create a new paste based on this one


Comments: