[ create a new paste ] login | about

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

C, pasted on May 6:
/* Bài 377/95/SBT Thầy NTTMK:Tìm số nguyên tố lớn nhất trong ma trận các số nguyên . 377.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
#include<limits.h>
#define bool

void nhapmatran(int 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("%d",&a[i][j]);
		}
	}
}

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

void timnguyentolonnhat(int a[MAX][MAX],int m,int n)
{
	int f,max=INT_MIN,Co;
	bool Co=false;
	printf("Cac so nguyen to trong ma tran la:\n");
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			f=1;
			if(a[i][j]<2)
			f=0;
			for(int k=2;k<=a[i][j]/2;k++)
			{
				if(a[i][j]%k==0)
				f=0;
			}
			if(f==1)
			{
			printf("%4d",a[i][j]);
				if(a[i][j]>max)
				{
					max=a[i][j];
					Co=true;
				}
			}
		}
	}
	if(Co==true)
	printf("\nSo nguyen to lon nhat la:%d\n",max);
	else
	printf("\nChang co so nguyen to nao ca\n");
}

void main()
{
	int a[MAX][MAX],m,n,f,max=INT_MIN,Co;
	bool Co=false;
	nhapmatran(a,m,n);
	xuatmatran(a,m,n);
	timnguyentolonnhat(a,m,n);
	getch();
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Line 17: error: conio.h: No such file or directory
Line 18: error: expected ';', ',' or ')' before '&' token
In function 'xuatmatran':
Line 48: error: 'for' loop initial declaration used outside C99 mode
Line 50: error: 'for' loop initial declaration used outside C99 mode
In function 'timnguyentolonnhat':
Line 61: error: 'false' undeclared (first use in this function)
Line 61: error: (Each undeclared identifier is reported only once
Line 61: error: for each function it appears in.)
Line 63: error: 'for' loop initial declaration used outside C99 mode
Line 65: error: 'for' loop initial declaration used outside C99 mode
Line 70: error: 'for' loop initial declaration used outside C99 mode
Line 81: error: 'true' undeclared (first use in this function)
In function 'main':
Line 95: error: 'false' undeclared (first use in this function)
Line 93: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: