ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
Ejemplo025.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <time.h>
4
5
#define BIT(n) (1<<(n))
6
#define BIT_GET(x,n) ((x) & BIT(n))
7
#define BIT_SET(x,n) ((x) |= BIT(n))
8
#define BIT_CLEAR(x,n) ((x) &= ~BIT(n))
9
#define BIT_TOGGLE(x,n) ((x) ^= BIT(n))
10
#define BIT_WRITE(x,n,v) ((v)?BIT_SET(x,n):BIT_CLEAR(x,n))
11
#define ES_PAR(x) (!BIT_GET(x,0))
12
#define N 50
13
14
int
main
(
int
argc,
char
*argv[])
15
{
16
char
str[
N
], c, p, v;
17
int
i, nc, cc, cb;
18
srand(time(NULL));
19
i = 0;
20
do
{
21
c = getchar();
22
str[i] = c;
23
i++;
24
}
while
(c!=10&&i<(
N
-1));
25
nc = i-1;
26
str[nc] =
'\0'
;
27
p = 0;
28
i = 0;
29
while
(str[i]!=
'\0'
)
30
{
31
p^=str[i];
32
i++;
33
}
34
printf(
"%s (%d)\n"
, str, p);
35
cc = (rand()%nc);
36
cb = (rand()%8);
37
BIT_TOGGLE
(str[cc],cb);
38
v = p;
39
i = 0;
40
while
(str[i]!=
'\0'
)
41
{
42
v^=str[i];
43
i++;
44
}
45
printf(
"%s (%d, %d, %d)\n"
, str, v, cc, cb);
46
return
0;
47
}
N
#define N
Definition
012_aleatorio.c:5
BIT_TOGGLE
#define BIT_TOGGLE(x, n)
Definition
Ejemplo025.c:9
main
int main(void)
Definition
Ejemplo_035.c:15
src
20252
Ejemplo025.c
Generated by
1.16.1