-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.c
More file actions
129 lines (105 loc) · 2.08 KB
/
program.c
File metadata and controls
129 lines (105 loc) · 2.08 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
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
/*
Do not modify this file.
Make all of your changes to main.c instead.
*/
#include "program.h"
#include <stdio.h>
#include <stdlib.h>
static int compare_bytes(const void *pa, const void *pb)
{
int a = *(char *)pa;
int b = *(char *)pb;
if (a < b)
{
return -1;
}
else if (a == b)
{
return 0;
}
else
{
return 1;
}
}
void alpha_program(char *data, int length)
{
int total = 0;
int i, j;
srand48(38290);
for (i = 0; i < length; i++)
{
data[i] = 0;
}
for (j = 0; j < 100; j++)
{
int start = lrand48() % length;
int size = 25;
for (i = 0; i < 100; i++)
{
data[(start + lrand48() % size) % length] = lrand48();
}
}
for (i = 0; i < length; i++)
{
total += data[i];
}
printf("alpha result is %d\n", total);
}
void beta_program(char *data, int length)
{
int total = 0;
int i;
srand48(4856);
for (i = 0; i < length; i++)
{
data[i] = lrand48();
}
qsort(data, length, 1, compare_bytes);
for (i = 0; i < length; i++)
{
total += data[i];
}
printf("beta result is %d\n", total);
}
void gamma_program(char *cdata, int length)
{
unsigned i, j;
unsigned char *data = (unsigned char *)cdata;
unsigned total = 0;
for (i = 0; i < length; i++)
{
data[i] = i % 256;
}
for (j = 0; j < 10; j++)
{
for (i = 0; i < length; i++)
{
total += data[i];
}
}
printf("gamma result is %d\n", total);
}
void delta_program(char *cdata, int length)
{
unsigned i, j;
unsigned char *data = (unsigned char *)cdata;
unsigned total = 0;
for (i = 0; i < length; i++)
{
data[i] = i % 256;
}
for (j = 0; j < 10; j++)
{
for (i = 0; i < length; i++)
{
total += data[i];
}
// error fixed 04/10/2018
for (i = length - 1; i > 0; i--)
{
total += data[i];
}
}
printf("delta result is %d\n", total);
}