[ create a new paste ] login | about

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

C, pasted on May 5:
/* Bài 162/62/SBT:Cho mảng một chiều các số thực.Hãy viết hàm tìm một vị trí trong mảng thỏa hai điều kiện:Có hai giá trị lân cận và giá trị tại vị trí đó bằng tích hai giá trị lân cận.Nếu như mảng không tồn tại giá trị như vậy thì hàm trả về giá trị -1. 139.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
#define bool

void nhapmang (float 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("%f",&a[i]);
	}
}

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

void xulydulieu(float a[MAX],int n)
{
    int vitri=0,Co,dem=0;
    bool Co=false;
	printf("Vi tri thoa man yeu cau cua bai toan la:");
    for(int i=2;i<n;i++)
    {
       float b=a[i]*a[i-2];
        if(a[i-1]==b)
        {
			printf("%4d",i-1);
			dem++;
			Co=true;
        }
    }
    if(Co==true)
    printf("\nTrong mang co %d vi tri thoa man yeu cau cua bai toan",dem);
	else
	printf("\n-1");
}

void main()
{
	float a[MAX];
	int n,NAMSON;
	quaylai:nhapmang(a,n);
	xuatmang(a,n);
	xulydulieu(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
Line 17: error: conio.h: No such file or directory
Line 17: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 37: error: 'for' loop initial declaration used outside C99 mode
In function 'xulydulieu':
Line 47: error: 'false' undeclared (first use in this function)
Line 47: error: (Each undeclared identifier is reported only once
Line 47: error: for each function it appears in.)
Line 49: error: 'for' loop initial declaration used outside C99 mode
Line 56: error: 'true' undeclared (first use in this function)
In function 'main':
Line 66: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: