[ create a new paste ] login | about

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

C, pasted on May 6:
/* Bài 297/79/SBT Thầy NTTMK:Tính tổng từng mảng con tăng trong mảng một chiều các số thực . NAMSON: 254.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(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)
{
	for(int i=0;i<n;i++)
	{
		printf("%16f",a[i]);
	}
	printf("\n");
}


int kiemtramangtang(float b[MAX], int nb)
{
	for(int i=0; i<nb-1; i++)
	{
		if (b[i]>b[i+1])
			return 0;
	}
	return 1;
}

float tongmangcon(float b[MAX], int nb)
{
	float s=0;
	for (int i=0; i<nb; i++)
	{
		s = s + b[i];
	}
	return s;
} 

void xuatmangcon(float b[MAX], int nb)
{
	for(int i=0; i<nb; i++)
	{
		printf("%16f", b[i]);
	}
}

void lietkecontang(float a[MAX], int n)
{
	int ChieuDai;
	int  nb;
	float tong;
	float b[MAX];
	for (int i=0; i<n; i++)
	{
		for (ChieuDai = 1+i; ChieuDai<=n; ChieuDai++)
		{
			nb=0;
			for(int j=i; j<ChieuDai; j++)
			{
				b[nb]=a[j];
				nb++;
			}
			if (kiemtramangtang(b,nb)==1)
			{
				xuatmangcon(b,nb);
				tong=tongmangcon(b,nb);
				printf("\tTong la:%f",tong);
				printf("\n");
			}
		}
	}
} 

void main()
{
	float a[MAX],tong;
	int n,tieptuc;
	quaylai:nhapmang(a,n);
	printf("\n>>>>>>>>>>>>MANG VUA NHAP LA:<<<<<<<<<<<<<\n");
	xuatmang(a,n);
	printf("\n>>>>>>>>>>>>>CAC MANG CON TANG LA:<<<<<<<<<<<<<<<<<\n");
	lietkecontang(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
14
15
Line 17: error: conio.h: No such file or directory
Line 16: error: expected ';', ',' or ')' before '&' token
In function 'xuatmang':
Line 35: error: 'for' loop initial declaration used outside C99 mode
In function 'kiemtramangtang':
Line 45: error: 'for' loop initial declaration used outside C99 mode
In function 'tongmangcon':
Line 56: error: 'for' loop initial declaration used outside C99 mode
In function 'xuatmangcon':
Line 65: error: 'for' loop initial declaration used outside C99 mode
In function 'lietkecontang':
Line 77: error: 'for' loop initial declaration used outside C99 mode
Line 82: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 99: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: