[ create a new paste ] login | about

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

C, pasted on May 5:
/* Bài 164/62/SBT Thầy NTTMK:Cho mảng một chiều các số nguyên hãy viết hàm tìm giá trị đầu tiên trong mảng thỏa tính chất số gánh.(ví dụ:12321). 141.cpp */

/* Ở đây chương trình liệt kê ra tất cả các giá trị số gánh có trong mảng,đếm số lượng của chúng.Liệt kê ra số gánh đầu tiên trong mảng kèm theo vị trí của nó. */

/* LƯU Ý:VỚI NHỮNG DẠNG BÀI MÀ PHẢI ĐẶT TRƯỜNG HỢP SỐ a[i] CHẠY TRONG 1 ĐOẠN NÀO ĐÓ ĐỂ TA MUỐN TÌM RA CÁC CHỮ SỐ RIÊNG BIỆT CỦA a[i] THÌ TA CHỈ DÙNG ĐƯỢC PHÉP CHIA,TUYỆT ĐỐI KHÔNG CÓ PHÉP TRỪ TRONG ĐÓ. */
/* 

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
#define bool

void nhapmang(int a[MAX],int &n)
{
	do{
	printf("Nhap vao so phan tu cua mang: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]);
	}
}

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

void lietke(int a[MAX],int n)
{
	int Co;
	bool Co=false;
	int dem,demb=0,demc=0,deme=0,demj=0,demo=0;
	printf("Cac gia tri trong mang thoa tinh chat so ganh la:");
	for(int i=0;i<n;i++)
	{
		if(a[i]>=-9&&a[i]<=9)
		{
				printf("%4d",a[i]);
				demb++;
				Co=true;
		}
		if(a[i]>=10&&a[i]<=99)
		{
			int c=a[i]/10;
			int d=a[i]%10;
			if(c==d)
			{
				printf("%4d",a[i]);
				demc++;
				Co=true;
			}
		}
		if(a[i]>=100&&a[i]<=999)
		{
			int e=a[i]/100;
			int g=a[i]%10;
			if(e==g)
			{
				printf("%4d",a[i]);
				deme++;
				Co=true;
			}
		}
		if(a[i]>=1000&&a[i]<=9999)
		{
			int j=a[i]/1000;
			int k=a[i]%10;
			int l=a[i]/10;
			int m=l%10;
			int z=a[i]/100;
			int t=z%10;
			if(j==k&&m==t)
			{
				printf("%4d",a[i]);
				demj++;
				Co=true;
			}
		}
		if(a[i]>=10000&&a[i]<=99999)
		{
			int o=a[i]/10000;
			int p=a[i]%10;
			int q=a[i]/10;
			int r=q%10;
			int s=a[i]/1000;
			int u=s%10;
			if(o==p&&r==u)
			{
				printf("%4d",a[i]);
				demo++;
				Co=true;
			}
		}
	}
	dem=demb+demc+deme+demj+demo;
	if(Co==true)
	printf("\nTrong mang co %d gia tri thoa man yeu cau de bai",dem);
	else
	printf("\nKhong co gia tri nao trong mang thoa man yeu cau de bai");
}

void dautien(int a[MAX],int n)
{
	int Co,vitri=0,i,Co1;
	bool Co=false;
	bool Co1=false;
	for(i=0;i<n;i++)
	{
		if(a[i]>=-9&&a[i]<=9)
		{
				Co=true;
		}
		if(a[i]>=10&&a[i]<=99)
		{
			int c=a[i]/10;
			int d=a[i]%10;
			if(c==d)
			{
				Co=true;
			}
		}
		if(a[i]>=100&&a[i]<=999)
		{
			int e=a[i]/100;
			int g=a[i]%10;
			if(e==g)
			{
				Co=true;
			}
		}
		if(a[i]>=1000&&a[i]<=9999)
		{
			int j=a[i]/1000;
			int k=a[i]%10;
			int l=a[i]/10;
			int m=l%10;
			int z=a[i]/100;
			int t=z%10;
			if(j==k&&m==t)
			{
				Co=true;
			}
		}
		if(a[i]>=10000&&a[i]<=99999)
		{
			int o=a[i]/10000;
			int p=a[i]%10;
			int q=a[i]/10;
			int r=q%10;
			int s=a[i]/1000;
			int u=s%10;
			if(o==p&&r==u)
			{
				Co=true;
			}
		}
		if(Co==true)
		{
			Co1=true;
			vitri=i;
			break;
		}
	}
	if(Co1==true)
		printf("\nSo dau tien trong mang thoa tinh chat so ganh la:%d tai vi tri:%d",a[i],vitri);
}

void main()
{
	int a[MAX],n,NAMSON;
	quaylai:nhapmang(a,n);
	xuatmang(a,n);
	lietke(a,n);
	dautien(a,n);
	printf("\nBan co muon tiep tuc chay chuong trinh khong ? Neu co bam phim C,nguoc lai bam bat ky phim nao khac de ket thuc\n");
	NAMSON=getch();
	if(NAMSON=='c'||NAMSON=='C')
		goto quaylai;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Line 17: error: conio.h: No such file or directory
Line 21: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 41: error: 'for' loop initial declaration used outside C99 mode
In function 'lietke':
Line 51: error: 'false' undeclared (first use in this function)
Line 51: error: (Each undeclared identifier is reported only once
Line 51: error: for each function it appears in.)
Line 54: error: 'for' loop initial declaration used outside C99 mode
Line 60: error: 'true' undeclared (first use in this function)
In function 'dautien':
Line 125: error: 'false' undeclared (first use in this function)
Line 131: error: 'true' undeclared (first use in this function)
In function 'main':
Line 189: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: