-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathga_a.c
More file actions
38 lines (33 loc) · 751 Bytes
/
ga_a.c
File metadata and controls
38 lines (33 loc) · 751 Bytes
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
/* ga_a.c ---some functions*/
#include "ga_a.h"
#include "ga_types.h"
#include "z_err.h"
#include <stdio.h>
#include <stdlib.h>
Genome newrandgenome(int dnanum) {
int i;
Genome a;
a.dna = malloc(dnanum);
if (a.dna == NULL)
error("cant malloc randgenome");
for (i = 0; i < dnanum; i++)
a.dna[i] = rand() % 256;
a.dnanum = dnanum;
return a;
}
void printgenome(Genome a, int dnanum) {
int i;
for (i = 0; i < dnanum; i++)
printf("%3d ", a.dna[i]);
}
void printarray(int a[], int n) {
int i;
for (i = 0; i < n; i++)
printf("%d ", a[i]);
puts("");
}
void copygenome(Genome dst, Genome src, int n) {
register int i;
for (i = 0; i < n; i++)
dst.dna[i] = src.dna[i];
}