pC.NET

Welcome to oscc.kr



 10진수 2진수로 변환하여 출력하기
2020-05-12 10:42:36
Hit : 1111

작성자 : 피시키드
- File #1 : 59.c(688 Byte), Download : 22

배열을 이용해서 8자리 묶음으로 저장하고 출력한다.

포인트는 printf()이용할 때 자릿수를 0으로 채우는 서식을 사용하는데 있다.

 

 

 

#include <stdio.h> // 2진수로 변환하기 // 배열을 이용하여 자리수 제한에서 벗어난다. int main() { inti; int j; int x; int cnt; int last = 0; int n = 1; int tmp; int s[100]; for (i=99;i>=0;i--) s[i] = 0; printf("input x: "); scanf("%d",&x); for (i=0;i<=99;i++) { cnt = -1; n = 1; while (x >= 1) { cnt = cnt + 1; tmp = x % 2; x = x / 2; s[i] = s[i] + tmp * n; n = n * 10; if (cnt >= 8) break; // printf("%d\n",x); } if ( x < 1) break; } last = i; printf("%d",s[last]); for (i=last-1;i>=0;i--) printf("%08d",s[i]); return 0; }

* 피시키드님에 의해서 게시물 이동되었습니다 (2024-04-26 18:49)

  피시키드
회원님의 소개글이 없습니다.
 6490
 83


문자열 좌우회전 이동
최대공약수 구하기(유클리드 호제법)

Copyright (C) 1997-2025 All Rights Reserved.

Powered by
DNS server, DNS service 우분투 리눅스 웹서비스 AbuseIPDB Contributor Badge