[ create a new paste ] login | about

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

C, pasted on May 6:
/* Bai 370/94/SBT Thay NTTMK:Tìm giá trị âm lớn nhất trong ma trận . 35.cpp  */
/* 

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

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

void nhapmatran(float a[MAX][MAX],int &m,int &n)
{
	do{
	printf("Nhap vao so dong: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: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("%f",&a[i][j]);
		}
	}
}

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

int AmDauTien(float a[MAX][MAX], int m, int n) 
{ 
    for (int i=0; i<m; i++) 
    { 
        for (int j=0; j<n; j++) 
        { 
            if (a[i][j]<0) 
            { 
                return a[i][j]; 
            } 
        } 
   } 
     return 0; 
}

int GiaTriCanTim(float a[MAX][MAX], int m, int n) 
{ 
   int AmMax = AmDauTien(a,m,n); 
   if (AmMax == 0) 
   { 
        return 0; 
   } 
   for (int i=0; i<m;i++) 
   { 
       for (int j=0; j<n; j++) 
       { 
           if (a[i][j]<0) 
           { 
               AmMax = (AmMax>a[i][j])?AmMax:a[i][j]; 
           } 
      } 
   } 
     return AmMax; 
} 

void main()
{
	float a[MAX][MAX];
	int m,n;
	nhapmatran(a,m,n);
	xuatmatran(a,m,n);
	float s=GiaTriCanTim(a,m,n);
	printf("So am lon nhat trong ma tran la:%f\n",s);
	getch();
}
	


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
Line 17: error: conio.h: No such file or directory
Line 16: error: expected ';', ',' or ')' before '&' token
In function 'xuatmatran':
Line 46: error: 'for' loop initial declaration used outside C99 mode
Line 48: error: 'for' loop initial declaration used outside C99 mode
In function 'AmDauTien':
Line 58: error: 'for' loop initial declaration used outside C99 mode
Line 60: error: 'for' loop initial declaration used outside C99 mode
In function 'GiaTriCanTim':
Line 78: error: 'for' loop initial declaration used outside C99 mode
Line 80: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 92: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: