Commit 8337d1a8 by trkall

suur kodune t66

parent 18f308e8
#include <stdio.h>
#include <stdlib.h>
void sisestus(double*, double*);
void rekursiiv(double*, int *, double, double);
double absoluutv22rtus(double);
double power(double, int);
void push(double*, int*, float);
void v2ljastus(double *, int n);
int main(void)
{
int n = 0;
double x, e;
double * A = malloc(sizeof(double));
sisestus(&x, &e);
push(A, &n, x);
rekursiiv(A, &n, x, e);
v2ljastus(A, n);
// programm lõpetas töö edukalt
return 0;
}
void sisestus(double *x, double *e)
{
do
{
printf("Sisesta reaalarvuline X (|x| < 1)");
scanf("%lf", x);
}
while(!(-1 < *x && *x < 1));
do
{
printf("Sisesta reaalarvuline e (0 < e <1)");
scanf("%lf", e);
}
while(!(0 < *e && *e < 1));
}
void rekursiiv(double *A, int *n, double x, double e)
{
double vahe = *(A+(*n-1)) -*(A+(*n-2));
if((*n) + 1 <= 15 && absoluutv22rtus(vahe) <= e)
{
double vv = power(x,((*n)+1)*2-1)/((double)(((*n)+1))*2-1);
push(A, n, vv);
rekursiiv(A, n, x, e);
}
}
double absoluutv22rtus(double v22rtus)
{
if(v22rtus < 0)
return -1.0f* v22rtus;
else
return v22rtus;
}
double power(double g, int h)
{
if(h > 0)
{
return g * power(g, h-1);
}
else return 1;
}
void v2ljastus(double *stack, int n)
{
char * outputFilename = "l6pptulemus.txt";
FILE *output;
output = fopen(outputFilename, "w");
fprintf(output, "Elementide arv: %d\n", n);
int i;
for(i = 0; i < n; i++)
{
fprintf(output, "%d) %.15lf\n",i, *(stack + i));
}
fclose(output);
}
void push(double *stack, int *n, float v22rtus)
{
double * temp = realloc(stack, sizeof(double)*(*n+1));
if(temp == NULL)
{
printf("Ei saa mälu eraldada!\n");
return;
}
stack = temp;
*n = *n + 1;
*(stack+(*n)-1) = v22rtus;
printf("%d)%.15lf\t%x\n", *n, *(stack +(*n)-1), stack +*n);
}
File added
#include <stdio.h>
#include <stdlib.h>
void sisestus(double*, double*);
void rekursiiv(double*, int *, double, double);
double absoluutv22rtus(double);
double power(double, int);
void push(double*, int*, float);
void v2ljastus(double *, int n);
int main(void)
{
int n = 0;
double x, e;
double * A = malloc(sizeof(double));
sisestus(&x, &e);
push(A, &n, x);
rekursiiv(A, &n, x, e);
v2ljastus(A, n);
// programm lõpetas töö edukalt
return 0;
}
void sisestus(double *x, double *e)
{
do
{
printf("Sisesta reaalarvuline X (|x| < 1)");
scanf("%lf", x);
}
while(!(-1 < *x && *x < 1));
do
{
printf("Sisesta reaalarvuline e (0 < e <1)");
scanf("%lf", e);
}
while(!(0 < *e && *e < 1));
}
void rekursiiv(double *A, int *n, double x, double e)
{
double vahe = *(A-*n-1) -*(A-*n-2);
if(((*n) + 1 <= 15) && (absoluutv22rtus(vahe) <= e))
{
double vv = power(x,((*n)+1)*2-1)/((double)(((*n)+1))*2-1);
push(A, n, vv);
rekursiiv(A, n, x, e);
}
}
double absoluutv22rtus(double v22rtus)
{
if(v22rtus < 0)
return -1.0f* v22rtus;
else
return v22rtus;
}
double power(double g, int h)
{
if(h > 0)
{
return g * power(g, h-1);
}
else return 1;
}
void v2ljastus(double *A, int n)
{
char * outputFilename = "l6pptulemus.txt";
FILE *output;
output = fopen(outputFilename, "w");
fprintf(output, "Elementide arv: %d\n", n);
int i;
for(i = 0; i < n; i++)
{
fprintf(output, "%d) %.15lf\n",i, *(A + i));
}
fclose(output);
}
void push(double *A, int *n, float v22rtus)
{
double * temp = realloc(A, sizeof(double)*(*n+1));
if(temp == NULL)
{
printf("Ei saa mälu eraldada!\n");
return;
}
A = temp;
*n = *n + 1;
*(A+(*n)-1) = v22rtus;
printf("%d)%.15lf\t%x\n", *n, *(A +(*n)-1), A +*n);
}
Elementide arv: 15
0) 0.899999976158142
1) 0.243000000715256
2) 0.118097998201847
3) 0.068328127264977
4) 0.043046720325947
5) 0.028528235852718
6) 0.019552813842893
7) 0.013726075179875
8) 0.009810106828809
9) 0.007109745871276
10) 0.005210428033024
11) 0.003853451460600
12) 0.002871592063457
13) 0.002153693931177
14) 0.001624182332307
#include <stdio.h>
#include <stdlib.h>
int L = 15;
int MAX = 1;
int MIN = 0;
/*
1. klaviatuurilt sisestatakse reaalarvulised X (|X|<1) ja e (0<e<1);
2. rekursiivse funktsiooni abil moodustatakse reaalarvuline massiiv A
elementidega
A1 = X,
A2 = X^3/3,
A3 = X^5/5,
. . .
kuni massiivi A elementide arv L kas vastab tingimusele |A[L] – A[L–1]| <=e või (kui see tingimus ei ole rahuldatud) L = 15;
3. faili F väljastatakse massiivi A elementide arv L ning elemendid
koos indeksitega.
*/
double aste(double, int);
double reku(double);
double absolutevodka(double);
void sisestus(double*, double*);
void rekursiiv(double*, int, double, double);
double absoluutv22rtus(double);
double power(double, int);
int push(double*, int, double);
void v2ljastus(double *, int n);
int main(void)
{
double x;
double e;
double* A = (double*)malloc(sizeof(double*));
printf("Sisestage x:");
scanf("%lf", &x);
printf("\nSisestage e:");
scanf("%lf", &e);
int n = 0;
double x, e;
double * A = (double*)malloc(sizeof(double));
sisestus(&x, &e);
n = push(A, n, x);
rekursiiv(A, n, x, e);
v2ljastus(A, n);
// programm lõpetas töö edukalt
return 0;
}
void sisestus(double *x, double *e)
{
do
{
printf("Sisesta reaalarvuline X (|x| < 1)");
scanf("%lf", x);
}
while(!(-1 < *x && *x < 1));
do
{
printf("Sisesta reaalarvuline e (0 < e <1)");
scanf("%lf", e);
}
while(!(0 < *e && *e < 1));
}
void rekursiiv(double *A, int n, double x, double e)
{
double vahe = 0;
if(n>1)
{
vahe = *(A+(n-1)) -*(A+(n-2));
}
if((n + 1) <= 15 && absoluutv22rtus(vahe) <= e)
{
double vv = power(x,(n+1)*2-1)/((double)((n+1))*2-1);
n = push(A, n, vv);
rekursiiv(A, n, x, e);
}
}
double absoluutv22rtus(double v22rtus)
{
if(v22rtus < 0)
return -1.0f* v22rtus;
else
return v22rtus;
}
double aste(double x, int y)
double power(double g, int h)
{
int i;
for (i = 1;i < y; i++)
if(h > 0)
{
x*=x;
return g * power(g, h-1);
}
return x;
else return 1;
}
double absolutevodka(double x)
void v2ljastus(double *A, int n)
{
if( x < 0)
char * outputFilename = "l6pptulemus.txt";
FILE *output;
output = fopen(outputFilename, "w");
fprintf(output, "Elementide arv: %d\n", n);
int i;
for(i = 0; i < n; i++)
{
x *= -1;
fprintf(output, "%d) %.15lf\n",i, *(A + i));
}
return x;
fclose(output);
}
int push(double *A, int n, double v22rtus)
{
A = (double*)realloc(A, sizeof(double*)*(1 + n));
n++;
*(A+(n-1)) = v22rtus;
printf("%d)%.15lf\t%x\n", n, *(A +(n-1)), *(A + n));
return n;
}
No preview for this file type
Elementide arv: 1
0) 0.900000000000000
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment