[ create a new paste ] login | about

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

C, pasted on May 6:
/* Bài 413/99/SBT Thầy NTTMK:Viết hàm sắp xếp các phần tử trong ma trận theo yêu cầu sau:
/* 

Tác giả: Nguyễn Việt Nam Sơn
Trung tâm đào tạo tin học - Thiết kế phần mềm - Sơn Đẹp Trai: www.SonDepTrai.com

Nguồn source code này Tôi viết vào năm 2012 lúc mới bắt đầu học lập trình C/C++ nên một số cách sẽ không được tối ưu - Bạn chỉ nên dùng trên tinh thần tham khảo thôi nhé.
Mong giúp đỡ được Bạn trên con đường Học Lập Trình.
TẤT CẢ VÌ SỰ THÀNH CÔNG CỦA BẠN

*/
-Dòng có ch s chn tăng dn.
-Dòng có ch s l gim dn. 316.cpp */

#include<stdio.h>
#include<conio.h>
#define MAX 100

void nhapmatran(int a[MAX][MAX],int &n,int &m)
{
	do{
		printf("Nhap vao so dong cua ma tran:m=");
		scanf("%d",&m);
		if(m<1||m>MAX)
			printf("So dong ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		else
			break;
	}while(m<1||m>MAX);
	do{
		printf("Nhap vao so cot cua ma tran:n=");
		scanf("%d",&n);
		if(n<1||n>MAX)
			printf("So cot ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		else
			break;
	}while(n<1||n>MAX);
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			printf("Nhap vao a[%d][%d]=",i,j);
			scanf("%d",&a[i][j]);
		}
	}
}

void xuatmatran(int a[MAX][MAX],int n,int m)
{
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			printf("%4d",a[i][j]);
		}
		printf("\n");
	}
}

void sapxepdongchantangdonglegiam(int a[MAX][MAX],int n,int m)
{
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(i%2==0)
				{
					if(a[i][j]>a[i][k])
					{
						int temp=a[i][j];
						a[i][j]=a[i][k];
						a[i][k]=temp;
					}
				}
				else
				{
					if(a[i][j]<a[i][k])
					{
						int temp=a[i][j];
						a[i][j]=a[i][k];
						a[i][k]=temp;
					}
				}
			}
		}
	}
}

void main()
{
	int a[MAX][MAX],n,m,x,tieptuc;
	quaylai:nhapmatran(a,n,m);
	printf("\n>>>>>>>>>>>>>>>MA TRAN VUA NHAP LA:<<<<<<<<<<<<<<<<<<<<<\n");
	xuatmatran(a,n,m);
	printf("\n>>>>>>>>>>>>>>>>MA TRAN SAP XEP DONG CHI SO CHAN TANG DAN,DONG CHI SO LE GIAM DAN:<<<<<<<<<<<<<<<<<<<<\n");
	sapxepdongchantangdonglegiam(a,n,m);
	xuatmatran(a,n,m);
	printf("\nBan co muon tiep tuc chay chuong trinh khong ? Neu co bam phim C,nguoc lai bam bat ky 1 phim nao khac de ket thuc\n");
	tieptuc=getch();
	if(tieptuc=='c'||tieptuc=='C')
		goto quaylai;
}


Output:
Line 12: error: expected identifier or '(' before '-' token
Line 12: error: stray '\303' in program
Line 12: error: stray '\262' in program
Line 12: error: stray '\303' in program
Line 12: error: stray '\263' in program
Line 12: error: stray '\341' in program
Line 12: error: stray '\273' in program
Line 12: error: stray '\211' in program
Line 12: error: stray '\341' in program
Line 12: error: stray '\273' in program
Line 12: error: stray '\221' in program
Line 12: error: stray '\341' in program
Line 12: error: stray '\272' in program
Line 12: error: stray '\265' in program
Line 12: error: stray '\304' in program
Line 12: error: stray '\203' in program
Line 12: error: stray '\341' in program
Line 12: error: stray '\272' in program
Line 12: error: stray '\247' in program
Line 13: error: stray '\303' in program
Line 13: error: stray '\262' in program
Line 13: error: stray '\303' in program
Line 13: error: stray '\263' in program
Line 13: error: stray '\341' in program
Line 13: error: stray '\273' in program
Line 13: error: stray '\211' in program
Line 13: error: stray '\341' in program
Line 13: error: stray '\273' in program
Line 13: error: stray '\221' in program
Line 13: error: stray '\341' in program
Line 13: error: stray '\272' in program
Line 13: error: stray '\273' in program
Line 13: error: stray '\341' in program
Line 13: error: stray '\272' in program
Line 13: error: stray '\243' in program
Line 13: error: stray '\341' in program
Line 13: error: stray '\272' in program
Line 13: error: stray '\247' in program
Line 41: error: invalid suffix "cpp" on floating constant
Line 17: error: conio.h: No such file or directory
In function 'xuatmatran':
Line 49: error: 'for' loop initial declaration used outside C99 mode
Line 51: error: 'for' loop initial declaration used outside C99 mode
In function 'sapxepdongchantangdonglegiam':
Line 61: error: 'for' loop initial declaration used outside C99 mode
Line 63: error: 'for' loop initial declaration used outside C99 mode
Line 65: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 91: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: