-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspoly_test.c
305 lines (262 loc) · 5.96 KB
/
spoly_test.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
#include "spoly.h"
#include <stdio.h>
void func1(){
printf("Input power-1 for the first polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput power-1 for the second polinom m=");
unsigned m;
scanf("%u",&m);
SPoly *arr2 =create(m);
input(arr2);
printf("\n");
print(arr2);
unsigned size;
if(n>=m) size=n;
if(m>n) size=m;
SPoly *arr =create(size);
arr=summary(arr1,arr2);
printf("\n(");
print(arr1);
printf(")+(");
print(arr2);
printf(")=");
print(arr);
printf("\n");
}
void func2(){
printf("Input power-1 for the first polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput power-1 for the second polinom m=");
unsigned m;
scanf("%u",&m);
SPoly *arr2 =create(m);
input(arr2);
printf("\n");
print(arr2);
unsigned size;
if(n>=m) size=n;
if(m>n) size=m;
SPoly *arr =create(size);
arr=subtraction(arr1,arr2);
printf("\n(");
print(arr1);
printf(")-(");
print(arr2);
printf(")=");
print(arr);
printf("\n");
}
void func3(){
printf("Input power-1 for the first polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput power-1 for the second polinom m=");
unsigned m;
scanf("%u",&m);
SPoly *arr2 =create(m);
input(arr2);
printf("\n");
print(arr2);
unsigned size;
if(n==1&& m==1) size=1;
if(m!=1 || n!=1) size=m*n-1;
SPoly *arr =create(size);
arr=multiply(arr1,arr2);
printf("\n(");
print(arr1);
printf(")*(");
print(arr2);
printf(")=");
print(arr);
printf("\n");
}
void func4(){
printf("Input power-1 for the first polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput power-1 for the second polinom m=");
unsigned m;
scanf("%u",&m);
SPoly *arr2 =create(m);
input(arr2);
printf("\n");
print(arr2);
unsigned size;
if(n==1&& m==1) size=1;
if(m!=1 || n!=1) size=n-m+1;
SPoly *arr =create(size);
arr=devide(arr1,arr2);
SPoly* ost=create(n);
ost=devide_ost(arr1,arr2);
printf("\n(");
print(arr1);
printf(")/(");
print(arr2);
printf(")=(");
print(arr);
printf(")+(ost");
print(ost);
printf(")\n");
}
void func5(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput const for the the integration polinom const=");
double c;
scanf("%lf",&c);
unsigned size=n+1;
SPoly *arr =create(size);
arr=integration(arr1,c);
printf("\nintegrate(");
print(arr1);
printf("+%.2lf",c);
printf("=");
print(arr);
printf("\n");
}
void func6(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nIntegral:");
print(integration(arr1,0));
printf("\nInput: a=");
double a;
scanf("%lf",&a);
printf("\nInput: b=");
double b;
scanf("%lf",&b);
double result=integration_value(arr1,a,b);
printf("\nintegrate from a to b(");
print(arr1);
printf(")=");
printf("%lf\n",result);
}
void func7(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
unsigned size=n-1;
SPoly *arr =create(size);
arr=derivative(arr1);
printf("\n(");
print(arr1);
printf(")'=");
print(arr);
printf("\n");
}
void func8(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
unsigned size=n-1;
SPoly *arr =create(size);
arr=derivative(arr1);
printf("\n(");
print(arr1);
printf(")'=");
print(arr);
printf("\n");
printf("Input x=");
double x;
scanf("%lf",&x);
double value=derivative_value(arr1,x);
printf("Derivative in point=%lf\n",value);
}
void func9(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print(arr1);
printf("\nInput x=");
double x;
scanf("%lf",&x);
double value=value_in_point(arr1,x);
printf("Value in point=%lf\n",value);
}
void func10(){
printf("VEnter the polinom, if coeficient =0, input 0x^n:\n");
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input_str(arr1);
print(arr1);
printf("\n");
}
void func11(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input(arr1);
printf("\n");
print_file(arr1,"spoly_file.txt");
}
void func12(){
printf("Input power-1 of polinom n=");
unsigned n;
scanf("%u",&n);
SPoly *arr1 =create(n);
input_file(arr1,"spoly_file.txt");
print(arr1);
printf("\n");
}
int main(){
printf("Menu:\n1-Sum \n2-Substruction \n3-Multiply\n4-division\n5-integrate\n6-definit integrate\n7-derivative\n8-derivative in point\n9-value in point\n10-input polinom in a row\n11-print polinom in file\n12-input from file\n0-break\n");
int action;
while(action>0){
printf("Input number of action:");
scanf("%d",&action);
if(action==1) func1();
if(action==2) func2();
if(action==3) func3();
if(action==4) func4();
if(action==5) func5();
if(action==6) func6();
if(action==7) func7();
if(action==8) func8();
if(action==9) func9();
if(action==10) func10();
if(action==11) func11();
if(action==12) func12();
}
}