[ create a new paste ] login | about

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

C, pasted on May 19:
#include<stdio.h>
#include<conio.h>
void DoiSangHe2()
{
	 int SoHe10, SoDu, Thuong;
	int SoHe2[100], i = 1, j;

	printf("\nNhap vao so he 10: ");
	scanf_s("%d", &SoHe10);

	Thuong = SoHe10;
	while (Thuong != 0)
	{
		SoHe2[i++] = Thuong % 2;
		Thuong /= 2;
	}
	printf("Gia tri he 2 tuong duong he 10 cua so %d: ", SoHe10);
	for (int j = i - 1; j > 0; j--)
	{
		printf("%d", SoHe2[j]);
	}
}
void DoiSangHe8()
{
	int SoHe10, SoDu, Thuong;
	int SoHe8[100], i = 1, j;

	printf("\nNhap vao so he 10: ");
	scanf_s("%d", &SoHe10);

	Thuong = SoHe10;
	while (Thuong != 0)
	{
		SoHe8[i++] = Thuong % 8;
		Thuong /= 8;
	}
	printf("Gia tri he 8 tuong duong he 10 cua so %d: ", SoHe10);
	for (int j = i - 1; j > 0; j--)
	{
		printf("%d", SoHe8[j]);
	}
}
void DoiSangHe16()
{
	int SoHe10, SoDu, Thuong;
	int SoHe16[100], i = 1, j,temp;

	printf("\nNhap vao so he 10: ");
	scanf_s("%d", &SoHe10);

	Thuong = SoHe10;
	while (Thuong != 0)
	{
		temp = Thuong % 16;
		
		// chuyển từ kiểu số sang kiểu ký tự
		if (temp < 10)
			temp = temp + 48;
		else
			temp = temp + 55;
		SoHe16[i++] = temp;
		Thuong /= 16;
	}
	printf("Gia tri he 16 tuong duong he 10 cua so %d: ", SoHe10);
	for (int j = i - 1; j > 0; j--)
	{
		printf("%c", SoHe16[j]);
	}
}
void DoiHe(int x, int He)
{
	int SoHe10[3], SoDu, Thuong[3] = { Thuong[0] = 2, Thuong[1] = 8, Thuong[2] = 16 };
	int SoHe[100], i = 1, j, temp;

	printf("\nNhap vao so he 10: ");
	scanf_s("%d", &SoHe10);

}

int main()
{
	DoiSangHe2();
	DoiSangHe8();
	DoiSangHe16();
	//DoiHe(250,2);
	_getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
Line 17: error: conio.h: No such file or directory
In function 'DoiSangHe2':
Line 18: error: redeclaration of 'j' with no linkage
Line 6: error: previous declaration of 'j' was here
Line 18: error: 'for' loop initial declaration used outside C99 mode
In function 'DoiSangHe8':
Line 38: error: redeclaration of 'j' with no linkage
Line 26: error: previous declaration of 'j' was here
Line 38: error: 'for' loop initial declaration used outside C99 mode
In function 'DoiSangHe16':
Line 65: error: redeclaration of 'j' with no linkage
Line 46: error: previous declaration of 'j' was here
Line 65: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: