-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_3_final.l
More file actions
executable file
·85 lines (77 loc) · 1.96 KB
/
class_3_final.l
File metadata and controls
executable file
·85 lines (77 loc) · 1.96 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
%{
#include<stdio.h>
#include<math.h>
int a,b;
int choice;
float x;
%}
%%
. ;
%%
int yywrap(void){ }
int main() {
printf("1) Addition\n2) Subtraction\n3) Multiplication\n4) Division\n");
printf("5) Sin(X)\n6) Cos(X)\n7) Tan(X)\n");
printf("8) Square\n9) Square-Root\n");
printf("10) Positive|Negative|Zero\n");
scanf("%d", &choice);
if(choice > 0 && choice < 5) {
printf("\nEnter A:\n");
scanf("%d", &a);
printf("Enter B:\n");
scanf("%d", &b);
printf("\n");
switch(choice)
{
case 1:
printf("A+B = %lf", (a+b));
break;
case 2:
printf("A-B = %lf", (a-b));
break;
case 3:
printf("A*B = %lf", (a*b));
break;
case 4:
printf("A/B = %lf", (a/b));
break;
default:
printf("Not valid");
break;
}
}
else {
// do trigonometry
printf("\nEnter X:\n");
scanf("%f", &x);
switch(choice)
{
case 5:
printf("sin(%f) = %f", x, sin(x));
break;
case 6:
printf("cos(%f) = %f", x, cos(x));
break;
case 7:
printf("tan(%f) = %f", x, tan(x));
break;
case 8:
printf("Square(%f) = %f", x, x*x);
break;
case 9:
double result = sqrt(x);
printf("Square Root(%f) = %f", x, result);
break;
case 10:
if(x > 0) printf("\nPositive");
else if(x < 0) printf("\nNegative");
else printf("Zero");
break;
default:
printf("Not valid");
break;
}
}
yylex();
return 1;
}