Submission
Status:
PPPPPPPPPP
Score: 100
User: Buktep
Problemset: แปลงเลขฐาน
Language: c
Time: 0.001 second
Submitted On: 2024-10-16 18:50:05
#include <stdio.h>
void convert(int hex)
{
int arr[16];
int c = 0;
if (hex == 0)
{
arr[c++] = 0;
}
else
{
while (hex > 0)
{
arr[c++] = hex % 2;
hex /= 2;
}
}
for (int i = c - 1; i >= 0; i--)
{
printf("%d", arr[i]); //n - 1 to 0.
}
}
int main()
{
unsigned int hex;
scanf("%x", &hex); //hex -> dec (unsigned int hex)
convert(hex);
printf("\n%o", hex);
return (0);
}