Skip to content
Snippets Groups Projects
Commit 6948d424 authored by Jason R Wilson's avatar Jason R Wilson
Browse files

files for lecture 7

parent 38448133
No related merge requests found
#include <stdio.h>
typedef struct vec2_s {
double x,y;
} vec2;
void vec2_add (vec2 a, vec2 b, vec2 c) {
c.x = a.x + b.x;
c.y = a.y + b.y;
}
int main () {
vec2 u = { 1.0, 2.0 };
vec2 v = { 2.0, 3.0 };
vec2 w = { 0, 0 };
vec2_add(u,v,w);
printf ("%.2f %.2f\n",w.x,w.y);
}
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char* argv[]) {
if (argc < 2) {
printf ("command usage: %s %s\n",argv[0],"n");
return 1;
}
int n = atoi(argv[1]);
int num_pairs = 0;
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
if (i<j) {
num_pairs += 1;
}
}
}
printf ("There are %d possible pairs of %d points.\n",num_pairs,n);
}
import sys
import numpy as np
import matplotlib.pyplot as plt
# the name of the output file is a command line argument
if (len(sys.argv) < 2):
print ("Command Usage : python3",sys.argv[0],"outfile")
exit(1)
outfile = sys.argv[1]
# read the data file
data = np.loadtxt(sys.stdin)
# plot the data
plt.gca().set_aspect('equal')
plt.scatter(data[:,0],data[:,1],s=10,color='black')
# plot the special points (if additional command line argments present)
for k in range(2,len(sys.argv)):
i = int(sys.argv[k])
plt.scatter (data[i,0],data[i,1],s=100,color='orange')
# save the plot as an image
plt.savefig(outfile)
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char* argv[]) {
if (argc < 2) {
printf ("command usage: %s %s\n",argv[0],"n");
return 1;
}
int n = atoi(argv[1]);
for (int i=0;i<n-1;i++) {
for (int j=i+1;j<n;j++) {
printf ("%d %d\n",i,j);
}
}
}
-0.285285 -0.249789
0.549825 -0.44841
0.264675 0.662557
-0.371575 0.51916
0.149416 0.025386
-0.260369 -0.079527
-0.088467 0.377545
-0.368702 0.54827
-0.568275 0.732792
-0.882076 0.426153
-0.494966 -0.419666
0.588019 -0.542201
-0.659639 0.521633
0.546128 -0.458203
-0.201864 0.90729
-0.445202 0.510424
-0.923883 0.213152
-0.178604 -0.134069
0.819752 0.46694
-0.643817 -0.506508
-0.28429 -0.05856
0.053874 -0.072568
-0.393404 0.525293
-0.825468 0.558931
0.98147 0.156388
-0.212288 -0.012805
-0.822678 -0.061019
-0.043017 0.120938
-0.420571 -0.443652
0.186023 -0.923548
0.084594 0.184044
-0.050319 -0.571804
-0.779859 0.26342
-0.209462 -0.641269
0.725177 0.487428
-0.292593 -0.402471
-0.49277 0.192058
-0.139183 0.799168
0.162535 0.156179
0.541549 0.704283
0.806409 0.230459
-0.379849 0.901739
0.472613 0.376156
-0.487109 0.80138
-0.715723 -0.519908
-0.056526 -0.560174
0.277816 -0.385239
-0.658979 -0.596906
0.749273 -0.315245
-0.252612 0.112699
0.810477 -0.099938
0.605109 -0.659443
-0.410374 -0.79696
0.26155 0.377804
0.939656 0.232053
-0.147269 -0.848126
-0.243183 -0.420227
0.04209 -0.172037
0.877444 0.083776
-0.474773 0.587203
0.580906 0.480285
-0.202889 -0.927574
-0.16257 -0.429955
0.225387 -0.063909
0.436523 0.526416
-0.157312 -0.203698
0.695396 0.146272
-0.210177 0.923684
0.381408 -0.647416
0.089079 -0.331767
0.623849 -0.624408
-0.235582 0.930326
-0.535296 0.149174
-0.102852 -0.636314
-0.639046 -0.241586
-0.608494 -0.174415
-0.035015 -0.219017
-0.553866 -0.323574
-0.283451 0.121833
-0.433664 0.853236
-0.831121 -0.318238
0.202378 -0.062011
-0.832565 0.206383
0.603159 -0.121344
-0.15034 -0.064065
-0.90493 -0.303486
-0.290074 0.260181
0.178954 0.792372
-0.762596 -0.456936
0.956249 0.274787
-0.152215 0.558616
-0.243961 -0.687811
-0.033381 -0.886103
-0.147454 -0.781676
-0.658208 0.285903
0.273236 0.215035
-0.22018 0.548046
-0.102578 0.60073
-0.860222 0.39712
-0.063284 0.960043
#include <stdio.h>
typedef struct vec100k_s {
double x[100000];
} vec100k;
vec100k vec100k_set (vec100k a, int i, double b) {
a.x[i] = b;
return a;
}
int main () {
vec100k v;
for (int i=0;i<100000;i++) {
v = vec100k_set (v,i,i);
}
printf ("x[12345] = %.2f",v.x[12345]);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment