-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw82.cpp
81 lines (61 loc) · 1.13 KB
/
hw82.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
이진수 만들기 위하여 data.txt에서
정수 1개를 읽어서 몫을 계속
다시 2로 나누어 나머지만 출력하라
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE* fp;
fopen_s(&fp, "data.txt", "r");
fscanf_s(fp, "%d", &num);
printf("%d\n", num);
int namoji;
int mok=0;
printf("%d\n",num);
mok = num; //mok =123
int i = 0;
int tmp1[100], tmp2[100];
while (1)
{
tmp1[i] = mok % 2;
mok = mok / 2;
printf("나머지: %d\n", tmp1[i]);
i++;
if (mok == 0)
{
printf("끝\n");
break;
}
}
for (int j = 0; j < i; j++) {
printf("[%d] %d\n",j, tmp1[j]);
}
for (int j = 0; j < i; j++)
{
tmp2[j] = tmp1[i - j-1];
}
printf("------역배열------\n");
for (int j = 0; j < i; j++)
{
printf("%d\n", tmp2[j]);
}
printf("------배열 확인-----\n");
for (int j = 0; j < i; j++)
{
printf("%d\n", tmp1[j]);
}
int check = 0;
int one = 1;
for (int j = 0; j < i; j++)
{
check = check + (tmp1[j] * one);
printf("check: %d\n", check);
one = one * 2;
}
printf("%d\n", check);
fclose(fp);
return 0;
}