[C / C ] Show us some 2, Contacts 8, Contacts 16 of decimal

To display of system 10 to other systems, usually we think of how we change the algorithm with other systems. If you want so you can find on Google has many articles about the algorithm then, here he set a certain way that we do not need to use algorithms that can display immediately.

CEO: Enter 1 Some systems 10 then output system 16.

#include <stdio.h>
#include <stdlib.h>

void Hex(int n) 
{
	if (n < 16) 	
	{
		printf("%c","0123456789ABCDEF"[n]);	// hien thi ky tu thu n trong chuoi
		return;
	} 
	else Hex(n / 16);
	printf("%c","0123456789ABCDEF"[n % 16]);
}

int main() {
	int n;
	printf("Enter your number: ");
	scanf("%d", &n);
	printf("Number in hex:");
	Hex(n);
	return 0;
}

If you look closely, in the code above we use the algorithm still divided 16 Using recursive. This applies also good for us 2 and Us 8. Also we can use the function to convert ltoa (the search yourself).
So do not use algorithms then how? Simple as follows:

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n;
	printf("Enter your number: ");
	scanf("%d", &n);
	printf("Number in hex: %X", n); // in ra so Hex bang dinh dang %X
	return 0;
}

Simple and concise not? :D.

More information:
To perform some kind of something as a certain number of systems: for example, you enter a whole number now want to perform it on the screen.
– Generation format 10 use% d
– Generation format 8 use% o
– Generation format 16 use% x (or X to uppercase letters)

Notice, we can enter the number system 16 or system 8 and print out the system 8, 10, 16 you want.
VD into the system 16 print out of system 8, Contacts 10.

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n;
	printf("Enter your number in Hex: ");
	scanf("%x", &n);
	printf("Number in Oct: %on", n);
	printf("Number in Dec: %dn", n);
	return 0;
}

KQ:

Enter your number in Hex: D2F
Number in Oct: 6457
Number in Dec: 3375

Refer to:
The difference between% d and% i in C programming
Print out the hex
convert a decimal number to Contacts 16 or system 2, fastest way