[ create a new paste ] login | about

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

C, pasted on May 19:
#include<stdio.h>
#include<conio.h>
#define MAX 100
void NhapMang(int a[], int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("\nNhap vao phan tu a[%d] = ", i);
		scanf_s("%d", &a[i]);
	}
}
void XuatMang(int a[], int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%4d", a[i]);

	}
}

void DemChuSo(int a[], int n, int b[])
{
	// Duyệt mảng a
	for (int i = 0; i < n; i++)
	{
		int themang = a[i];
		while (themang != 0)
		{
			int ChuSo = themang % 10;
			themang /= 10;

			b[ChuSo]++;
		}
	}
}
int main()
{
	int n;
	do
	{
		printf("\nNhap vao so luong phan tu cua mang: ");
		scanf_s("%d", &n);
		if (n < 0 || n > MAX)
		{
			printf("\nSo luong phan tu khong hop le. Xin kiem tra lai !");
		}
	} while (n < 0 || n > MAX);

	int a[MAX];
	NhapMang(a, n);
	XuatMang(a, n);

	int b[10] = { 0 };

	DemChuSo(a, n, b);
	
	for (int i = 0; i < 10; i++)
	{
		// Chỉ xét những chữ số có số lần xuất hiện > 0
		if (b[i] != 0)
		{
			printf("\nChu so %d xuat hien %d lan", i, b[i]);

		}
	}

	_getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
Line 17: error: conio.h: No such file or directory
In function 'NhapMang':
Line 6: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMang':
Line 14: error: 'for' loop initial declaration used outside C99 mode
In function 'DemChuSo':
Line 24: error: 'for' loop initial declaration used outside C99 mode
In function 'main':
Line 57: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: