-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_13.c
153 lines (126 loc) · 2.54 KB
/
3_13.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define MSJ_FUERA_DE_RANGO "El dato ingresado no se encuentra"
#define MSJ_ERROR "ERROR"
#define MSJ_PROB_A "La probabilidad A es"
#define MSJ_PROB_B "La probabilidad B es"
/**************************probabilia a***************************/
int probabilidad_a (void){
int g;
float P;
srand (time (NULL));
P=(float) rand()/RAND_MAX ;
if (0<P && P<=0.2){
g=0;
}
else if (0.2<P && P<=1){
g=1;
}
else printf("%s\n", MSJ_FUERA_DE_RANGO );
return g;
}
/*************************************probabilidad b*********************/
int probabilidad_b (void){
float a;
srand (time (NULL));
a=(float) rand()/RAND_MAX;
if (0<a && a<=0.1){
return 3;
}
else if (0.1<a && a<=0.65){
return 5;
}
else if (0.65<a && a<= 1){
return 9;
}
else
printf("%s\n", MSJ_FUERA_DE_RANGO );
return -1;
}
/******************************moneda****************************/
#define MSJ_MONEDA_HEAD "HEAD"
#define MSJ_MONEDA_TAIL "TAIL"
typedef enum {
HEAD, TAIL
}lado_t;
int moneda (void)
{
int a;
srand (time (NULL));
a=rand();
a=a%2;/*el resto va a ser 0 o 1*/
switch (a){
case (0):
return 0;
break;
case (1):
return 1;
break;
default:
return -1;
break;
}
}
void imprimir_moneda (void){
int l;
l=moneda();
switch (l){
case(0):
printf("%s\n", MSJ_MONEDA_HEAD );
break;
case(1):
printf("%s\n", MSJ_MONEDA_TAIL);
break;
default:
break;
}
}
/******************************dado**********************/
#define DBJ_0 "| |"
#define DBJ_1_LEFT "|* |"
#define DBJ_1_MIDDLE "| * |"
#define DBJ_1_RIGHT "| *|"
#define DBJ_2 "|* *|"
int tirar_dado (void){
int c;
srand (time (NULL));
c=rand();
c=(c%6)+1;
return c;
}
int imprimir_dado (int c){
switch (c)
{
case (1):
printf(" %s\n %s\n %s\n",DBJ_0, DBJ_1_MIDDLE, DBJ_0 );
break;
case (2):
printf(" %s\n %s\n %s\n",DBJ_1_RIGHT, DBJ_0, DBJ_1_LEFT );
break;
case (3):
printf(" %s\n %s\n %s\n",DBJ_1_LEFT, DBJ_1_MIDDLE, DBJ_1_RIGHT );
break;
case (4):
printf(" %s\n %s\n %s\n",DBJ_2, DBJ_0, DBJ_2 );
break;
case (5):
printf(" %s\n %s\n %s\n",DBJ_2, DBJ_1_MIDDLE, DBJ_2 );
break;
case (6):
printf(" %s\n %s\n %s\n",DBJ_2, DBJ_2, DBJ_2 );
break;
default:
fprintf(stderr, "%s\n", MSJ_FUERA_DE_RANGO);
break;
}
return EXIT_SUCCESS;
}
int main (void){
printf("%s %i\n",MSJ_PROB_A , probabilidad_a() );
printf("%s %i\n",MSJ_PROB_B , probabilidad_b() );
imprimir_moneda();
imprimir_dado(tirar_dado() ) ;
return 0;
}