[ create a new paste ] login | about

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

C, pasted on May 5:
/* Bài 236/81/SBT Thầy NTTMK:Cho hai mảng a và b.Hãy đếm số lần xuất hiện của mảng a trong mảng b ? . NAMSON: 266.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 nhapmang(int a[MAX],int b[MAX],int &n,int &m)
{
	do{
		printf("Nhap vao so phan tu cua mang A:n=");
		scanf("%d",&n);
		if(n<1||n>MAX)
			printf("So ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		else
			break;
	}while(n<1||n>MAX);
	for(int i=0;i<n;i++)
	{
		printf("Nhap vao a[%d]=",i);
		scanf("%d",&a[i]);
	}
	do{
		printf("Nhap vao so phan tu cua mang B:m=");
		scanf("%d",&m);
		if(m<1||m>MAX)
			printf("So ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		else
			break;
	}while(m<1||m>MAX);
	for(int j=0;j<m;j++)
	{
		printf("Nhap vao b[%d]=",j);
		scanf("%d",&b[j]);
	}
}

void xuatmang(int a[MAX],int b[MAX],int n,int m)
{
	printf("\n>>>>>>>>>>>>>>>>>>MANG A VUA NHAP LA:<<<<<<<<<<<<<<<<<<<<\n");
	for(int i=0;i<n;i++)
	{
		printf("%4d",a[i]);
	}
	printf("\n");
	printf("\n>>>>>>>>>>>>>>>>>>MANG B VUA NHAP LA:<<<<<<<<<<<<<<<<<<<<\n");
	for(int j=0;j<m;j++)
	{
		printf("%4d",b[j]);
	}
	printf("\n");
}

int Dem(int a[MAX], int b[MAX], int n, int m)
{
	int i,j,test,dem=0;
	for (i=0; i<m; i++)
	{
		if (b[i]==a[0])
		{
			int h = i;
			for (test=1, j=0; j<n;j++,h++)
			{
				if (a[j] != b[h])
				{
					test = 0;
					break;
				}
			}
			if (test == 1)
				dem++;
		}
	}
	return dem;
} 

void main()
{
	int a[MAX],b[MAX],n,m,tieptuc;
	quaylai:nhapmang(a,b,n,m);
	xuatmang(a,b,n,m);
	int s=Dem(a,b,n,m);
	if(s==1)
		printf("\nSo lan xuat hien cua mang A trong mang B la:%d",s);
	else
		printf("\nNO");
	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:
1
2
3
4
5
6
7
Line 17: error: conio.h: No such file or directory
Line 16: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 49: error: 'for' loop initial declaration used outside C99 mode
Line 55: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 86: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: