[ create a new paste ] login | about

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

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

// Ma trận zic zac ngang
void XuatMaTran(int a[][MAX], int d, int c)
{
	for (int i = 0; i < d ; i++)
	{
		for (int j = 0; j < c; j++)
		{
			printf("%4d", a[i][j]);
		}
		printf("\n\n");
	}
}

void TaoMaTranZicZacNgang(int a[][MAX],int dong, int cot)
{
	int dem=1;
	for(int i = 0; i < dong; i++)
	{
		if(i % 2 == 0)
			for(int j = 0; j < cot; j++)
				a[i][j] = dem++;
		else
			for(int j = cot-1; j >= 0; j--)
				a[i][j] = dem++;
	}
}

int main()
{
	int a[MAX][MAX];
	int dong, cot;
	do 
	{
		printf("\nNhap vao so dong: ");
		scanf("%d", &dong);

		if (dong < 0 || dong > MAX)
		{
			printf("\nChi so dong khong hop le. Xin kiem tra lai !");
		}
	} while (dong < 0 || dong > MAX);

	do 
	{
		printf("\nNhap vao so cot: ");
		scanf("%d", &cot);

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

	printf("\nMa tran xoan oc: \n");

	TaoMaTranZicZacNgang(a,dong,cot);
	XuatMaTran(a,dong,cot);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
Line 17: error: conio.h: No such file or directory
In function 'XuatMaTran':
Line 8: error: 'for' loop initial declaration used outside C99 mode
Line 10: error: 'for' loop initial declaration used outside C99 mode
In function 'TaoMaTranZicZacNgang':
Line 21: error: 'for' loop initial declaration used outside C99 mode
Line 24: error: 'for' loop initial declaration used outside C99 mode
Line 27: error: redefinition of 'j'
Line 24: error: previous definition of 'j' was here
Line 27: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: