[ create a new paste ] login | about

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

C, pasted on May 5:
/* Chuyển đổi từ hệ nhị phân sang hệ thập phân (số không dấu) 493.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>
#include<Windows.h>
#include<math.h>
#define MAX 100

void NhapMang(int a[MAX],int &n)
{
	quaylai:printf("\nNhap vao so phan tu cua mang:n=");
	scanf("%d",&n);
	if(n<1||n>MAX)
	{
		printf("\nSo ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		goto quaylai;
	}
	for(int i=0;i<n;i++)
	{
		quaylai1:printf("\nNhap vao a[%d]=",i);
		scanf("%d",&a[i]);
		if(a[i]!=0&&a[i]!=1)
		{
			printf("\nGia tri ban nhap khong hop le!Xin vui long nhap lai!\n");
			goto quaylai1;
		}
	}
}

void XuatMang(int a[MAX],int n)
{
	for(int i=0;i<n;i++)
	{
		printf("%4d",a[i]);
	}
	printf("\n");
}

void ChuyenSangHe10(int a[MAX],int n)
{
	int tong=0;
	for(int i=0;i<n;i++)
	{
		tong+=a[i]*pow(2.0,n-1-i);
	}
	printf("\nHe thap phan la:%d",tong);
}

void main()
{
	int a[MAX],n,tieptuc;
	quaylai:NhapMang(a,n);
	XuatMang(a,n);
	ChuyenSangHe10(a,n);
	printf("\nBan co muon tiep tuc chay chuong trinh hay 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')
	{
		system("cls");
		goto quaylai;
	}
}


Output:
1
2
3
4
5
6
7
8
9
Line 17: error: conio.h: No such file or directory
Line 19: error: Windows.h: No such file or directory
Line 18: error: expected ';', ',' or ')' before '&' token
In function 'XuatMang':
Line 41: error: 'for' loop initial declaration used outside C99 mode
In function 'ChuyenSangHe10':
Line 51: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 59: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: