language: AWK (mawk) (mawk-1.3.3)
date: 189 days 16 hours ago
link:
visibility: public
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
#include <stdio.h>
#include <math.h>
 
long double x_start, x_end, x_step, eps;
long double INF = 1e9;
long double function_1(long double arg)
{
        return cos(arg);
}
 
long double fact(int n)
{
        long double ans = 1, i;
        for(i = 2; i <= n; i++)
                ans *= i;
        return (ans);
}
 
long double function_2_pre(double arg, int steps)
{
        long double ans = 0;
        int i;
        if(steps < 0)
                return -1;
        for(i = 0; i < steps; i++)
        {
                long double temp = 2 * i;
                ans += (i % 2 == 0? 1 : -1) * (pow(arg, temp) / fact(2 * i)); 
        }
        return ans;
}
 
long double function_2(double arg)
{
        long double prev = -INF;
        int step = 0;
        long double cur = function_2_pre(arg, step);
        step++;
        while(fabs(prev - cur) >= eps)
        {
                prev = cur;
                cur = function_2_pre(arg, step);
                step++;
        }
        return cur;
}
 
int main()
{
        (void) scanf("%Lf %Lf %Lf %Lf", &x_start, &x_end, &x_step, &eps);
        if((x_start > x_end) || (floor((x_end - x_start) / x_step) - ceil((x_end - x_start) / x_step) >= eps)|| (x_step <= 0))
        {
                printf("No solution\n");
                return 0;
        }       
        long double x_iterator = x_start;
        printf("##===============#=======================#======================##\n"); 
        printf("|| \t X \t | \t cos\t      |\t tailor \t||\n");
        printf("##===============#=======================#======================##\n");         
        while(x_iterator <= x_end)
        {
                printf("|| %6Lf \t | \t %6Lf \t | \t %6Lf \t|| \n", x_iterator, function_1(x_iterator), function_2(x_iterator));
                x_iterator += x_step;
        }
 
        printf("##===============#=======================#======================##\n");         
        return 0;
}
  • upload with new input
  • result: Success     time: 0s    memory: 1952 kB     returned value: 2

    0 1 0.1 0.000001
    mawk: prog.awk: line 4: syntax error at or near ,
    mawk: prog.awk: line 8: return outside function body
    mawk: prog.awk: line 11: syntax error at or near n
    mawk: prog.awk: line 13: syntax error at or near =
    mawk: prog.awk: line 16: return outside function body