Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

trkall / iag0582

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 097713b6 authored 8 years ago by trkall's avatar trkall
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

kodune

parent 8337d1a8 master
Hide whitespace changes
Inline Side-by-side
Showing with 138 additions and 11 deletions
  • kodunet66_2/k.c
  • kodunet66_2/k.exe
  • kodunet66_2/k.o
  • kodunet66_2/l6pptulemus.txt
  • kt/k.c
  • kt/k.exe
  • kt/k.o
  • kt/l6pptulemus.txt
kodunet66_2/k.c
View file @ 097713b6
......@@ -5,18 +5,19 @@ void sisestus(double*, double*);
void rekursiiv(double*, int *, double, double);
double absoluutv22rtus(double);
double power(double, int);
void push(double*, int*, float);
void push(double*, int*, double);
void v2ljastus(double *, int n);
int main(void)
{
int n = 0;
double x, e;
double * A = malloc(sizeof(double));
double *A = (double*)malloc(sizeof(double));
sisestus(&x, &e);
push(A, &n, x);
rekursiiv(A, &n, x, e);
v2ljastus(A, n);
free(A);
// programm lõpetas töö edukalt
return 0;
}
......@@ -39,8 +40,8 @@ void sisestus(double *x, double *e)
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 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);
......@@ -65,7 +66,7 @@ double power(double g, int h)
else return 1;
}
void v2ljastus(double *stack, int n)
void v2ljastus(double *A, int n)
{
char * outputFilename = "l6pptulemus.txt";
FILE *output;
......@@ -74,21 +75,21 @@ void v2ljastus(double *stack, int n)
int i;
for(i = 0; i < n; i++)
{
fprintf(output, "%d) %.15lf\n",i, *(stack + i));
fprintf(output, "%d) %.15lf\n",i, *(A + i));
}
fclose(output);
}
void push(double *stack, int *n, float v22rtus)
void push(double *A, int *n, double v22rtus)
{
double * temp = realloc(stack, sizeof(double)*(*n+1));
double *temp = (double*)realloc(A, sizeof(double*)*(1 + (*n)));
if(temp == NULL)
{
printf("Ei saa mälu eraldada!\n");
return;
}
stack = temp;
A = temp;
*n = *n + 1;
*(stack+(*n)-1) = v22rtus;
printf("%d)%.15lf\t%x\n", *n, *(stack +(*n)-1), stack +*n);
*(A+((*n)-1)) = v22rtus;
///printf("%d)%.15lf\t%x\n", *n, *(A +((*n)-1)), *(A +(*n))); ///.15lf
}
This diff is collapsed. Click to expand it.
kodunet66_2/k.exe
View file @ 097713b6
No preview for this file type
This diff is collapsed. Click to expand it.
kodunet66_2/k.o
View file @ 097713b6
No preview for this file type
This diff is collapsed. Click to expand it.
kodunet66_2/l6pptulemus.txt 0 → 100644
View file @ 097713b6
Elementide arv: 15
0) 0.100000000000000
1) 0.000333333333333
2) 0.000002000000000
3) 0.000000014285714
4) 0.000000000111111
5) 0.000000000000909
6) 0.000000000000008
7) 0.000000000000000
8) 0.000000000000000
9) 0.000000000000000
10) 0.000000000000000
11) 0.000000000000000
12) 0.000000000000000
13) 0.000000000000000
14) 0.000000000000000
This diff is collapsed. Click to expand it.
kt/k.c 0 → 100644
View file @ 097713b6
#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)*15);
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);
}
This diff is collapsed. Click to expand it.
kt/k.exe 0 → 100644
View file @ 097713b6
File added
This diff is collapsed. Click to expand it.
kt/k.o 0 → 100644
View file @ 097713b6
File added
This diff is collapsed. Click to expand it.
kt/l6pptulemus.txt 0 → 100644
View file @ 097713b6
Elementide arv: 15
0) 0.100000001490116
1) 0.000333333329763
2) 0.000001999999995
3) 0.000000014285714
4) 0.000000000111111
5) 0.000000000000909
6) 0.000000000000008
7) 0.000000000000000
8) 0.000000000000000
9) 0.000000000000000
10) 0.000000000000000
11) 0.000000000000000
12) 0.000000000000000
13) 0.000000000000000
14) 0.000000000000000
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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