[ create a new paste ] login | about

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

C, pasted on Jun 8:
#include<stdio.h>
#include<conio.h>
#define MAX 100
int i,j;
void NhapMaTran(int a[][MAX], int n)
{
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			printf("\nNhap vao a[%d][%d] = ", i, j);
			scanf("%d", &a[i][j]);
		}
	}
}
void XuatMaTran(int a[][MAX], int n)
{
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			printf("%4d",a[i][j]);
		}
		printf("\n\n");
	}
}
void DuyetCacPhanTuTrenDuongCheoChinh(int a[][MAX], int n)
{
	for(int i = 0; i < n; i++)
	{
		printf("%4d",a[i][i]);
	}
	
}
void DuyetCacPhanTuTamGiacTrenDuongCheoChinh(int a[][MAX], int n)
{
	for(int i = 0; i < n - 1; i++)
	{
		for(int j = i + 1; j < n; j++)
		{
			printf("%4d",a[i][j]);
		}
	}
	
}
void DuyetCacPhanTuTamGiacDuoiDuongCheoChinh(int a[][MAX], int n)
{
	/*for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < i; j++)
		{
			printf("%4d",a[i][j]);
		}
	}*/
	for(int i = 1; i < n; i++)
	{
		for(int j = i - 1; j >= 0; j--)
		{
			printf("%4d",a[i][j]);
		}
	}
	
}
int DemSoChanTamGiacDuoi(int a[][MAX], int n)
{
	int dem = 0;
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < i; j++)
		{
			if(a[i][j] % 2 == 0)
			{
				dem++;
			}
		}
	}
	return dem;
}
void DuyetCacPhanTuTrenDuongCheoPhu(int a[][MAX], int n)
{
	for(int i = 0; i < n; i++)
	{
	printf("%4d",a[i][n - 1 - i]);
	}
}
void DuyetCacPhanTuTamGiacTrenDuongCheoPhu(int a[][MAX], int n)
{
	for(int i = 0; i < n - 1; i++)
	{
		for(int j = 0; j < n - 1 - i; j++)
		{
			printf("%4d",a[i][j]);
		}
	}
	
}
void DuyetCacPhanTuTamGiacDuoiDuongCheoPhu(int a[][MAX], int n)
{
	for(int i = 1; i < n; i++)
	{
		for(int j = n - i; j < n; j++)
		{
			printf("%4d",a[i][j]);
		}
	}
	
}
int main()
{
	int a[MAX][MAX], n;

	do
	{
		printf("\nNhap vao so dong = so canh: ");
		scanf("%d", &n);
		if(n < 1 || n > MAX)
		{
			printf("\nChi so nhap vao khong hop le. Xin kiem tra lai !");
		}
	}while (n < 1 || n > MAX);

	NhapMaTran(a,n);
	XuatMaTran(a,n);

	printf("\nCac phan tu tren duong cheo chinh la: ");
	DuyetCacPhanTuTrenDuongCheoChinh(a,n);

	printf("\nCac phan tu tam giac tren duong cheo chinh la: ");
	DuyetCacPhanTuTamGiacTrenDuongCheoChinh(a,n);

	printf("\nCac phan tu tam giac duoi duong cheo chinh la: ");
	DuyetCacPhanTuTamGiacDuoiDuongCheoChinh(a,n);


	printf("\nCac phan tu tren duong cheo phu la: ");
	DuyetCacPhanTuTrenDuongCheoPhu(a,n);

	printf("\nCac phan tu tam giac tren duong cheo phu la: ");
	DuyetCacPhanTuTamGiacTrenDuongCheoPhu(a,n);

	printf("\nCac phan tu tam giac duoi duong cheo phu la: ");
	DuyetCacPhanTuTamGiacDuoiDuongCheoPhu(a,n);


	int dem = DemSoChanTamGiacDuoi(a,n);
	printf("\nSo luong phan tu chan tam giac duoi duong cheo chinh la %d",dem);
	getch();
	return 0;
}


Output:
Line 17: error: conio.h: No such file or directory
In function 'NhapMaTran':
Line 7: error: 'for' loop initial declaration used outside C99 mode
Line 9: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMaTran':
Line 18: error: 'for' loop initial declaration used outside C99 mode
Line 20: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTrenDuongCheoChinh':
Line 29: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTamGiacTrenDuongCheoChinh':
Line 37: error: 'for' loop initial declaration used outside C99 mode
Line 39: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTamGiacDuoiDuongCheoChinh':
Line 55: error: 'for' loop initial declaration used outside C99 mode
Line 57: error: 'for' loop initial declaration used outside C99 mode
In function 'DemSoChanTamGiacDuoi':
Line 67: error: 'for' loop initial declaration used outside C99 mode
Line 69: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTrenDuongCheoPhu':
Line 81: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTamGiacTrenDuongCheoPhu':
Line 88: error: 'for' loop initial declaration used outside C99 mode
Line 90: error: 'for' loop initial declaration used outside C99 mode
In function 'DuyetCacPhanTuTamGiacDuoiDuongCheoPhu':
Line 99: error: 'for' loop initial declaration used outside C99 mode
Line 101: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: