본문 바로가기
정보과학

2진수로 변환하기

by chaechaekim 2019. 5. 24.
#include <stdio.h>
int n, d[32];
int main()
{
	int i=0;
	scanf("%d", &n);
	
	do
	{
		d[i]=n%2;
		n/=2;
		i++;
	}while(n);
	
	while(i)
	{
		i--;
		printf("%d", d[i]);
	}
	
	printf("\n");
}

/*

11
1011

--------------------------------
Process exited after 4.311 seconds with return value 0
계속하려면 아무 키나 누르십시오 . . .

*/

'정보과학' 카테고리의 다른 글

n*n 배열에 저장하여 출력하기  (0) 2019.06.05
문자 shift  (0) 2019.05.31
숫자카운터  (0) 2019.05.22
숫자 맞히기 게임  (0) 2019.05.17
중첩반복을 이용한 숫자 삼각형 출력  (0) 2019.04.26

댓글