main
test-branch
|
Last change
on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
806 bytes
|
| Line | |
|---|
| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 |
|
|---|
| 4 | typedef struct {int * a; int n;} vector;
|
|---|
| 5 |
|
|---|
| 6 | vector *vector_init(vector * v, int n) {
|
|---|
| 7 | v->a = malloc(n*sizeof(int));
|
|---|
| 8 | v->n = n;
|
|---|
| 9 | for (int i = 0; i < n; ++i) v->a[i] = 0;
|
|---|
| 10 | return v;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | // program 1:
|
|---|
| 14 | vector *vector_addin(vector * a, const vector *b){// vector a += b;
|
|---|
| 15 | for (int i = 0; i < b->n; ++i)
|
|---|
| 16 | a->a[i] = (a->a[i] + b->a[i])%3;
|
|---|
| 17 | return a;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | int main(){
|
|---|
| 21 | int n = 8;
|
|---|
| 22 | vector x; vector_init(&x, n);
|
|---|
| 23 | vector y; vector_init(&y, n);
|
|---|
| 24 | for (int i = 0; i < x.n; ++i) { x.a[i] = i%3; y.a[i] = (i/3)%3; }
|
|---|
| 25 |
|
|---|
| 26 | vector_addin(&x, &y);
|
|---|
| 27 |
|
|---|
| 28 | int error = 0;
|
|---|
| 29 | for (int i = 0; i < x.n; ++i) if (x.a[i] != (i+i/3)%3) error += 1;
|
|---|
| 30 | if (error) printf("Unsliced Error\n");
|
|---|
| 31 | else printf("Unsliced Good\n");
|
|---|
| 32 | #ifdef _CIVL
|
|---|
| 33 | free(x.a);
|
|---|
| 34 | free(y.a);
|
|---|
| 35 | #endif
|
|---|
| 36 | return error ? -1 : 0;
|
|---|
| 37 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.