[ create a new paste ] login | about

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

C, pasted on Jan 10:
#include <stdio.h>
#include <conio.h>

void HoanVi(int *a, int *b)
{
	int trungGian = *a;
	*a = *b;
	*b = trungGian;
}

int main()
{
	int N, n, a[5], dem = 0, i, vtMax = 0, vtMin = 0;
	long M = 0, S;
	
	do{
		printf("Nhap N nguyen duong: ");
		scanf("%d", &N);
	}while(N <= 0);
	
	n = N;
	while(n != 0)
	{
		a[dem] = n % 10;
		n /= 10;
		dem++;
	}
	for(i = 0; i < dem / 2; i++)
		HoanVi(&a[i], &a[dem - i - 1]);
	for(i = 1; i < dem; i++)
	{
		if(a[i] > a[vtMax])
			vtMax = i;
		if(a[i] < a[vtMin])
			vtMin = i;
	}
	printf("Chu so lon nhat la %d, chu so nho nhat la %d", a[vtMax], a[vtMin]);
	
	HoanVi(&a[vtMax], &a[vtMin]);
	for(i = 0; i < dem; i++)
		M = M * 10 + a[i];	
	printf("\nSo M moi sau khi doi cho: %ld", M);
	
	S = M + N;
	printf("\nTong cua M va N: %ld", S);
	getch();
}


Output:
1
Line 18: error: conio.h: No such file or directory


Create a new paste based on this one


Comments: