-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasteregg.c
executable file
·349 lines (276 loc) · 5.97 KB
/
easteregg.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* This program does some handy handling of significant
figures that is handy for physics 152
Author: Bryce Lobdell
Email: blobdell@purdue.edu
Date: 2/11/99
*/
#include "stdio.h"
#include "math.h"
#define J 74
#define P 80
#define E 69
#define M 77
#define C 67
#define D 68
#define A 65
#define S 83
#define I 73
#define R 82
#define Q 81
#define HELP 63
char gospel[2000]=
{" Jesus replied, \"I am the bread of life. No one\n\
who comes to me will ever be hungry again. Those who\n\
believe in me will never thirst. But you haven't\n\
believed in me even though you have seen me. However,\n\
those the Father has given me will come to me, and I\n\
will never reject them. For I have come down from\n\
heaven to do the will of God who sent me, not to do\n\
what I want. And this is the will of God, that I\n\
should not lose even one of all those he has given me,\n\
but that I should raise them to eternal life at the\n\
last day. For it is my Father's will that all who see\n\
his Son and believe in him should have eternal - that I\n\
should raise them at the last day.\" (John 6:35-40)\n"};
#define uchar unsigned char
#define uint unsigned int
#define ulong unsinged long
struct number
{
float val;
float delta;
};
char *strupr(char *string)
{
int counter;
char *index;
counter = 0;
do {
index = string + counter;
if ((*index >= 97) && (*index <= 122))
*index -= 32;
counter++;
} while (*index != 0);
return string;
}
void shownum(struct number num)
{
printf("Val = %.12e \xF1 %.8e\n\n",num.val,num.delta);
}
struct number getnum(void)
{
struct number num;
printf("Number: ");
scanf("%f",&(num.val));
printf("Uncertainty: ");
scanf("%f",&(num.delta));
return num;
}
void help(void)
{
printf("Command Help:\nE Enter Data to Variable\nM Multiply\nD Divide\n");
printf("A Add\nS Subtract\nP Print Variable Data\nI Inverse\n");
printf("R Root\nC Clear Screen\nQ Quit\n\n");
}
struct number mult(struct number num1,struct number num2)
{
struct number num;
num.val = num1.val * num2.val;
num.delta = num.val * ((num1.delta/num1.val) + (num2.delta/num2.val));
return num;
}
struct number div(struct number num1,struct number num2)
{
struct number num;
num.val = num1.val / num2.val;
num.delta = num.val * ((num1.delta/num1.val) + (num2.delta/num2.val));
return num;
}
struct number add(struct number num1,struct number num2)
{
struct number num;
num.val = num1.val + num2.val;
num.delta = num1.delta + num2.delta;
return num;
}
struct number sub(struct number num1,struct number num2)
{
struct number num;
num.val = num1.val - num2.val;
num.delta = num1.delta + num2.delta;
return num;
}
struct number inv(struct number num)
{
num.delta = (1 / num.val) * (num.delta / num.val);
num.val = 1 / num.val;
return num;
}
struct number root(struct number num)
{
num.delta = num.delta / (2 * sqrt(num.val));
num.val = sqrt(num.val);
return num;
}
int selectvar(void)
{
int varnum;
char varstr[20];
printf("Select a Variable (A to Z): ");
scanf("%s",varstr);
strupr(varstr);
varnum = (int)varstr[0];
varnum -= 65;
if ((varnum < 0) || (varnum > 25))
varnum = -1;
return varnum;
}
main(void)
{
char command[20];
int quit,var1,var2,ans;
struct number variables[26];
quit = 1;
printf("PHYS 152 Uncertainty Math\n");
printf("Enter ? for help\n\n");
do {
scanf("%s",command);
strupr(command);
switch((int)(command[0]))
{
case (P):
{
var1 = selectvar();
if (var1 == -1)
{
printf("Not a valid Variable\n");
break;
}
shownum(variables[var1]);
break;
}
case (E):
{
var1 = selectvar();
if (var1 == -1)
{
printf("Invalid Variable\n");
break;
}
variables[var1] = getnum();
break;
}
case (M):
{
printf("Select 1st operand, 2nd operand and Answer Variables\n");
var1 = selectvar();
var2 = selectvar();
ans = selectvar();
if ((var1 == -1) || (var2 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = mult(variables[var1],variables[var2]);
shownum(variables[ans]);
break;
}
case (D):
{
printf("Select 1st operand, 2nd operand and Answer Variables\n");
var1 = selectvar();
var2 = selectvar();
ans = selectvar();
if ((var1 == -1) || (var2 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = div(variables[var1],variables[var2]);
shownum(variables[ans]);
break;
}
case (A):
{
printf("Select 1st operand, 2nd operand and Answer Variables\n");
var1 = selectvar();
var2 = selectvar();
ans = selectvar();
if ((var1 == -1) || (var2 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = add(variables[var1],variables[var2]);
shownum(variables[ans]);
break;
}
case (S):
{
printf("Select 1st operand, 2nd operand and Answer Variables\n");
var1 = selectvar();
var2 = selectvar();
ans = selectvar();
if ((var1 == -1) || (var2 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = sub(variables[var1],variables[var2]);
shownum(variables[ans]);
break;
}
case (I):
{
printf("Select operand and Answer Variables\n");
var1 = selectvar();
ans = selectvar();
if ((var1 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = inv(variables[var1]);
shownum(variables[ans]);
break;
}
case (C):
{
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
break;
}
case (R):
{
printf("Select operand and Answer Variables\n");
var1 = selectvar();
ans = selectvar();
if ((var1 == -1) || (ans == -1))
{
printf("Invalid Variable\n");
break;
}
variables[ans] = root(variables[var1]);
shownum(variables[ans]);
break;
}
case (Q):
{
quit = 0;
break;
}
case (J):
{
printf("%s\n",gospel);
break;
}
case (HELP):
{
help();
break;
}
default:
printf("Invalid Command\n");
}
} while (quit);
return 0;
}