Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #pragma warning (disable: 4996)
- #include "stdafx.h"
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- FILE *fw;
- double sz(double x, double delta, int m, char *przyczyna, int *ls);
- int _tmain(int argc, _TCHAR* argv[])
- {
- double a, b, a1, b1, n, p, x, y, x1, delta, z;
- int m, ls;//m-maksymalna liczba wyrazow szeregu ls-liczba sumowanych wyrazow szeregu
- char przyczyna;// przyczyna zakonczenia funkcji
- printf("Podaj przedzial [a,b], ilosc przedzialow n, maksymalna liczba wyrazow szeregu m oraz dokladnosc:\n");
- if (scanf("%lf %lf %lf %d %lf", &a, &b, &n, &m, &delta) != 5)
- {
- printf("Blad danych\n");
- system("pause");
- exit(1);
- }
- if (!(fw = fopen("wyniki.txt", "w")))
- {
- printf("Blad otwarcia zbioru\n");
- exit(2);
- }
- if (a > b)
- {
- a1 = b;
- b1 = a;
- }
- else if (a == b)
- {
- printf("Blad- zle podany przedzial\n");
- exit(3);
- }
- else
- {
- a1 = a;
- b1 = b;
- }
- if (n <= 0)
- {
- printf("Blad- ilosc przedzialow <=0\n");
- exit(4);
- }
- if (fabs(a1) > 1 || fabs(b1) > 1)
- {
- printf("Blad- wykorcznie poza dziezine");
- exit(5);
- }
- p = b1 - a1;
- for (x = a1; x <= b1 + 0.5*(p / n); x += (p / (n)))
- {
- y = sz(x, delta, m, &przyczyna, &ls);
- z = pow((1 - x), (-1. / 4));
- printf("x=%10.4lf\ty(x)=%10.5lf\t\t(1-x)^(-1/4)=%10.5lf\tDokladnosc osiagnieta:=%c\tls=%d\n", x, y, z, przyczyna, ls);
- printf("---------------------------------------------------------------------------\n");
- fprintf(fw, "x=%10.4lf\ty(x)=%10.5lf\t\tcos(x+c)=%10.5lf\tDokladnosc osiagnieta:=%c\tls=%d\n", x, y, z, przyczyna, ls);
- fprintf(fw, "---------------------------------------------------------------------------------------\n");
- }
- fclose(fw);
- system("pause");
- return 0;
- }
- double sz(double x, double delta, int m, char *przyczyna, int *ls)
- {
- double s = 0, d;
- int n;
- n = 1;
- d = 0;
- s = 0;
- int i;
- i = 1;
- do {
- s += d;
- d = d*(i*x) / (4 * i);
- s += d;
- i += 4;
- n++;
- } while ((fabs(d) >= delta) && (n < m));
- if ((fabs(d) <= delta))
- *przyczyna = 'T';
- else
- *przyczyna = 'N';
- *ls = n;
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement