-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYiginIleDecimalBinaryDonusum.c
99 lines (86 loc) · 1.7 KB
/
YiginIleDecimalBinaryDonusum.c
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <stdlib.h>
#define Y_BOYUT 100
typedef struct node
{
int indis;
int eleman[Y_BOYUT];
}Yiginlar;
Yiginlar *YiginOlustur()
{
Yiginlar *yeni_yigin;
yeni_yigin = (Yiginlar*)malloc(sizeof(Yiginlar));
yeni_yigin->indis = 0;
return yeni_yigin;
}
int YiginDoluMu(Yiginlar *yeni_yigin)
{
if(yeni_yigin->indis >= Y_BOYUT)
return -1;
else
return 1;
}
int YiginBosMu(Yiginlar *yeni_yigin)
{
if(yeni_yigin->indis == 0)
return -1;
else
return 1;
}
void Cevir(Yiginlar *yeni_yigin, int sayi)
{
int digit;
while(sayi > 0)
{
digit = sayi%2;
YiginaEkle(yeni_yigin, digit);
sayi = sayi/2;
}
while(yeni_yigin->indis>0)
{
digit = YigindanCikar(yeni_yigin);
printf("%d ", digit);
}
}
int YiginaEkle(Yiginlar *yeni_yigin, int sayi)
{
if(YiginDoluMu == -1)
{
printf("Yigin Dolu !\n");
getch();
return -1;
}
else
{
yeni_yigin->eleman[yeni_yigin->indis] = sayi;
yeni_yigin->indis++;
return 1;
}
}
int YigindanCikar(Yiginlar *yeni_yigin)
{
int cikan_eleman;
if(YiginBosMu == -1)
{
printf("Yigin Bos !\n");
getch();
return -1;
}
else
{
yeni_yigin->indis--;
cikan_eleman = yeni_yigin->eleman[yeni_yigin->indis];
return cikan_eleman;
}
}
int main()
{
int sayi;
printf("Bir sayi giriniz : ");
scanf("%d", &sayi);
Yiginlar *yigin = YiginOlustur();
printf("\n");
Cevir(yigin, sayi);
printf("\n");
return 0;
}