-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
92 lines (73 loc) · 2.09 KB
/
main.c
File metadata and controls
92 lines (73 loc) · 2.09 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n, x, y, bit, i, j, sum0, sum1, array[6], k, a;
float sonuc, bolen, carpan;
srand(time(NULL));
n = rand() % 6 + 5;
for (j = 0; j < n; j++)
{
for (;;)
{
sum0 = 0;
sum1 = 0;
y = rand() % 3 + 1;
x = 5 - y;
array[0] = j + 1;
for (i = 1; i <= 5; i++)
{
bit = rand() % 2;
if (bit == 0)
{
sum0++;
}
if (bit == 1)
{
sum1++;
}
array[i] = bit;
}
if (sum1 + 1 == sum0 || sum0 + 1 == sum1)
{
printf("%d. Sayi: ", array[0], array[0]);
for (i = 1; i <= 5; i++)
{
printf("%d", array[i]);
}
printf("\t");
printf("x: %d y: %d", x, y);
sonuc = 0.0;
for (a = 1; a <= x; a++)
{
if (array[a] == 1)
{
carpan = 1.0;
for (k = 0; k < (x - a); k++)
{
carpan = carpan * 2.0;
}
sonuc = sonuc + carpan;
}
}
for (a = x + 1; a <= 5; a++)
{
if (array[a] == 1)
{
bolen = 2.0;
for (k = 0; k < a - (x + 1); k++)
{
bolen = bolen * 2.0;
}
sonuc = sonuc + (1.0 / bolen);
}
}
printf("\t sonuc: %.3f\n", sonuc);
break;
}
}
printf("\n");
}
return 0;
}