[ create a new paste ] login | about

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

C, pasted on May 5:
/* Bài 244/73/SBT Thầy NTTMK:Hãy kiểm tra mảng số nguyên có thỏa mãn tính chất sau không : "Mảng không có tồn tại số hoàn thiện lớn hơn 256".Nếu thỏa trả về 1,nếu không trả về 0 . 387.cpp */

/* Ý Tưởng:Ta sẽ đi tìm ra trong tất cả các số hoàn thiện có trong mảng,tìm ra số hoàn thiện lớn nhất (max).Nếu max>256 => trả về 0 do lúc này đã có số hoàn thiện lớn hơn 256 rồi,nếu max <=256 => trả về 1 do số lớn nhất mà còn không lớn hơn được 256 vậy thì tất cả các số còn lại đều <= 256 hết.Còn nếu trong mảng không tồn tại số hoàn thiện nào cả thì chương trình sẽ báo cho biết. */
/* 

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>
#include<limits.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 phan tu 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)
{
	for(int i=0;i<n;i++)
	{
		printf("%4d",a[i]);
	}
	printf("\n");
}

void kiemtra(int a[MAX],int n)
{
	int Co,tong,max=INT_MIN;
	bool Co=false;
	for(int i=0;i<n;i++)
	{
		tong=0;
		for(int k=1;k<a[i];k++)
		{
			if(a[i]%k==0)
			{
				tong+=k;
			}
		}
		if(tong==a[i]&&tong>max)
		{
			max=tong;
			Co=true;
		}
	}
	if(Co==true)
	{
		if(max>256)
			printf("\n0");
		else
			printf("\n1");
	}
	else
		printf("\nMang nay khong ton tai so hoan thien\n");
}

void main()
{
	int a[MAX],n,tieptuc;
	quaylai:nhapmang(a,n);
	printf("\n>>>>>>>>>>>>>>>>>>MANG VUA NHAP LA:<<<<<<<<<<<<<<<<<<<<<<\n");
	xuatmang(a,n);
	kiemtra(a,n);
	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
8
9
10
11
12
13
Line 17: error: conio.h: No such file or directory
Line 20: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 39: error: 'for' loop initial declaration used outside C99 mode
In function 'kiemtra':
Line 49: error: 'false' undeclared (first use in this function)
Line 49: error: (Each undeclared identifier is reported only once
Line 49: error: for each function it appears in.)
Line 50: error: 'for' loop initial declaration used outside C99 mode
Line 53: error: 'for' loop initial declaration used outside C99 mode
Line 63: error: 'true' undeclared (first use in this function)
In function 'main':
Line 78: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: