[ create a new paste ] login | about

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

C, pasted on May 5:
/* Bài 146/59/SBT Thầy NTTMK:Tìm "giá trị âm đầu tiên" trong mảng một chiều các số thực.Nếu mảng không có giá trị âm thì trả về giá trị -1. 123.cpp */

/* Ở đây chương trình còn cho phép liệt kê ra tất cả các số âm có trong mảng và số lượng của nó.Liệt kê ra vị trí của số âm đầu tiên.*/
/* 

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 ban 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 lietkeam(float a[MAX],int n)
{
	int dem=0,Co;
	bool Co=false;
	printf("\nCac gia tri am co trong mang la:");
	for(int i=0;i<n;i++)
	{
		if(a[i]<0)
		{
			printf("%16f",a[i]);
			dem++;
			Co=true;
		}
	}
	if(Co==true)
	printf("\nTrong mang co %d gia tri am",dem);
	else
	printf("\n-1");
}

void amdautien(float a[MAX],int n)
{
	int i,vitri=0,Co;
	bool Co=false;
	for(i=0;i<n;i++)
	{
		if(a[i]<0)
		{
			Co=true;
			vitri=i;
			break;
		}
	}
	if(Co==true)
	printf("\nGia tri am dau tien la:%f tai vi tri:%d",a[i],vitri);
}





void main()
{
	float a[MAX];
	int n,NAMSON;
	quaylai:nhapmang(a,n);
	xuatmang(a,n);
	lietkeam(a,n);
	amdautien(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 19: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 39: error: 'for' loop initial declaration used outside C99 mode
In function 'lietkeam':
Line 50: error: 'false' undeclared (first use in this function)
Line 50: error: (Each undeclared identifier is reported only once
Line 50: error: for each function it appears in.)
Line 52: error: 'for' loop initial declaration used outside C99 mode
Line 58: error: 'true' undeclared (first use in this function)
In function 'amdautien':
Line 70: error: 'false' undeclared (first use in this function)
Line 75: error: 'true' undeclared (first use in this function)
In function 'main':
Line 89: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: