Commit 0d9b75fe by trkall

Merge branch 'master' of http://gitlab.pld.ttu.ee/trkall/iag0582

k
parents c3437ad7 77f567c9
#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*, double);
void v2ljastus(double *, int n);
int main(void)
{
int n = 0;
double x, e;
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;
}
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, double v22rtus)
{
double *temp = (double*)realloc(A, (1 + (*n))*sizeof(double));
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))); ///.15lf
}
File added
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
#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);
}
File added
File added
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
#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
Elementide arv: 15
0) 0.000000000000000
1) 0.000000000000000
2) 0.000000000000000
3) 0.000000000000000
4) 0.000000000000000
5) 0.000000000000000
6) 0.000000000000000
7) 0.000000000000000
8) 0.000000000000000
9) 0.000000000000000
10) 0.000000000000000
11) 0.000000000000000
12) 0.000000000000000
13) 0.000000000000000
14) 0.000000000000000
#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 lpetas 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 = malloc(sizeof(double)*(*n+1));
if(temp == NULL)
{
printf("Ei saa mlu eraldada!\n");
return;
}
stack = temp;
*n = *n + 1;
*(stack+(*n)-1) = v22rtus;
printf("%d)%.15lf\t%x\n", *n, *(stack +(*n)-1), stack +*n);
}
#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
2014S 149438IASB IRT3930 5.0 4
2014S 149396IASB IRT3930 5.0 4
2014S 149430IASB IRT3930 5.0 0
2014S 149404IASB IRT3930 5.0 4
2014S 149417IASB IRT3930 5.0 5
2014S 149421IASB IRT3930 5.0 5
2014S 149389IASB IRT3930 5.0 5
2014S 149395IASB IRT3930 5.0 4
2014S 149434IASB IRT3930 5.0 5
2014S 149385IASB IRT3930 5.0 1
2014S 149401IASB IRT3930 5.0 2
2014S 149411IASB IRT3930 5.0 5
2014S 149439IASB IRT3930 5.0 1
2014S 149438IASB IAY0010 6.0 2
2014S 149396IASB IAY0010 6.0 3
2014S 149430IASB IAY0010 6.0 3
2014S 149421IASB IAY0010 6.0 4
2014S 149410IASB IAY0010 6.0 5
2014S 149389IASB IAY0010 6.0 5
2014S 149406IASB IAY0010 6.0 5
2014S 149434IASB IAY0010 6.0 4
2014S 149385IASB IAY0010 6.0 1
2014S 149401IASB IAY0010 6.0 5
2014S 149411IASB IAY0010 6.0 3
2014S 149439IASB IAY0010 6.0 2
2014S 149438IASB YMM3731 5.0 4
2014S 149380IASB YMM3731 5.0 4
2014S 149396IASB YMM3731 5.0 5
2014S 149430IASB YMM3731 5.0 2
2014S 149421IASB YMM3731 5.0 4
2014S 149410IASB YMM3731 5.0 5
2014S 149389IASB YMM3731 5.0 5
2014S 149406IASB YMM3731 5.0 5
2014S 149395IASB YMM3731 5.0 1
2014S 149434IASB YMM3731 5.0 5
2014S 149385IASB YMM3731 5.0 4
2014S 149425IASB YMM3731 5.0 5
2014S 149405IASB YMM3731 5.0 0
2014S 149401IASB YMM3731 5.0 0
2014S 149411IASB YMM3731 5.0 5
2014S 149439IASB YMM3731 5.0 2
2014S 149438IASB IAG0581 5.0 4
2014S 149380IASB IAG0581 5.0 4
2014S 149430IASB IAG0581 5.0 5
2014S 149417IASB IAG0581 5.0 5
2014S 149410IASB IAG0581 5.0 3
2014S 149389IASB IAG0581 5.0 5
2014S 149434IASB IAG0581 5.0 1
2014S 149385IASB IAG0581 5.0 5
2014S 149425IASB IAG0581 5.0 4
2014S 149405IASB IAG0581 5.0 3
2014S 149401IASB IAG0581 5.0 1
2014S 149411IASB IAG0581 5.0 5
2014S 149439IASB IAG0581 5.0 4
2015K 149438IASB IAG0582 5.0 4
2015K 149380IASB IAG0582 5.0 5
2015K 149396IASB IAG0582 5.0 5
2015K 149430IASB IAG0582 5.0 3
2015K 149404IASB IAG0582 5.0 5
2015K 149417IASB IAG0582 5.0 4
2015K 149421IASB IAG0582 5.0 2
2015K 149384IASB IAG0582 5.0 1
2015K 149378IASB IAG0582 5.0 4
2015K 149410IASB IAG0582 5.0 4
2015K 149389IASB IAG0582 5.0 4
2015K 149406IASB IAG0582 5.0 5
2015K 149395IASB IAG0582 5.0 0
2015K 149434IASB IAG0582 5.0 4
2015K 149385IASB IAG0582 5.0 0
2015K 149425IASB IAG0582 5.0 5
2015K 149405IASB IAG0582 5.0 5
2015K 149401IASB IAG0582 5.0 1
2015K 149411IASB IAG0582 5.0 4
2015K 149439IASB IAG0582 5.0 2
2015K 149438IASB IAF0041 5.0 4
2015K 149380IASB IAF0041 5.0 0
2015K 149396IASB IAF0041 5.0 5
2015K 149430IASB IAF0041 5.0 5
2015K 149404IASB IAF0041 5.0 4
2015K 149417IASB IAF0041 5.0 5
2015K 149421IASB IAF0041 5.0 5
2015K 149384IASB IAF0041 5.0 3
2015K 149378IASB IAF0041 5.0 5
2015K 149410IASB IAF0041 5.0 4
2015K 149389IASB IAF0041 5.0 1
2015K 149406IASB IAF0041 5.0 4
2015K 149395IASB IAF0041 5.0 3
2015K 149434IASB IAF0041 5.0 5
2015K 149385IASB IAF0041 5.0 5
2015K 149425IASB IAF0041 5.0 5
2015K 149405IASB IAF0041 5.0 0
2015K 149401IASB IAF0041 5.0 3
2015K 149411IASB IAF0041 5.0 4
2015K 149439IASB IAF0041 5.0 5
2015K 149438IASB ISC0011 5.0 1
2015K 149380IASB ISC0011 5.0 2
2015K 149396IASB ISC0011 5.0 4
2015K 149430IASB ISC0011 5.0 4
2015K 149404IASB ISC0011 5.0 1
2015K 149417IASB ISC0011 5.0 4
2015K 149421IASB ISC0011 5.0 4
2015K 149384IASB ISC0011 5.0 4
2015K 149378IASB ISC0011 5.0 1
2015K 149410IASB ISC0011 5.0 4
2015K 149389IASB ISC0011 5.0 5
2015K 149406IASB ISC0011 5.0 4
2015K 149395IASB ISC0011 5.0 3
2015K 149434IASB ISC0011 5.0 5
2015K 149385IASB ISC0011 5.0 1
2015K 149425IASB ISC0011 5.0 4
2015K 149405IASB ISC0011 5.0 5
2015K 149401IASB ISC0011 5.0 0
2015K 149411IASB ISC0011 5.0 4
2015K 149439IASB ISC0011 5.0 4
2015K 149438IASB YFR0020 6.0 2
2015K 149380IASB YFR0020 6.0 3
2015K 149396IASB YFR0020 6.0 5
2015K 149430IASB YFR0020 6.0 5
2015K 149404IASB YFR0020 6.0 3
2015K 149417IASB YFR0020 6.0 5
2015K 149421IASB YFR0020 6.0 0
2015K 149384IASB YFR0020 6.0 1
2015K 149378IASB YFR0020 6.0 4
2015K 149410IASB YFR0020 6.0 4
2015K 149389IASB YFR0020 6.0 3
2015K 149406IASB YFR0020 6.0 4
2015K 149395IASB YFR0020 6.0 3
2015K 149434IASB YFR0020 6.0 5
2015K 149385IASB YFR0020 6.0 5
2015K 149425IASB YFR0020 6.0 4
2015K 149405IASB YFR0020 6.0 2
2015K 149401IASB YFR0020 6.0 4
2015K 149411IASB YFR0020 6.0 3
2015K 149439IASB YFR0020 6.0 0
2015S 149438IASB IAG0090 5.0 3
2015S 149380IASB IAG0090 5.0 5
2015S 149396IASB IAG0090 5.0 3
2015S 149430IASB IAG0090 5.0 2
2015S 149404IASB IAG0090 5.0 5
2015S 149417IASB IAG0090 5.0 5
2015S 149421IASB IAG0090 5.0 5
2015S 149384IASB IAG0090 5.0 4
2015S 149378IASB IAG0090 5.0 2
2015S 149410IASB IAG0090 5.0 4
2015S 149389IASB IAG0090 5.0 4
2015S 149406IASB IAG0090 5.0 5
2015S 149395IASB IAG0090 5.0 4
2015S 149434IASB IAG0090 5.0 1
2015S 149385IASB IAG0090 5.0 4
2015S 149425IASB IAG0090 5.0 4
2015S 149405IASB IAG0090 5.0 5
2015S 149401IASB IAG0090 5.0 4
2015S 149411IASB IAG0090 5.0 5
2015S 149439IASB IAG0090 5.0 3
2015S 149438IASB IAY0520 5.0 5
2015S 149380IASB IAY0520 5.0 1
2015S 149396IASB IAY0520 5.0 5
2015S 149430IASB IAY0520 5.0 1
2015S 149404IASB IAY0520 5.0 5
2015S 149417IASB IAY0520 5.0 4
2015S 149421IASB IAY0520 5.0 4
2015S 149384IASB IAY0520 5.0 3
2015S 149378IASB IAY0520 5.0 5
2015S 149410IASB IAY0520 5.0 5
2015S 149389IASB IAY0520 5.0 5
2015S 149406IASB IAY0520 5.0 4
2015S 149395IASB IAY0520 5.0 0
2015S 149434IASB IAY0520 5.0 4
2015S 149385IASB IAY0520 5.0 5
2015S 149425IASB IAY0520 5.0 4
2015S 149405IASB IAY0520 5.0 4
2015S 149401IASB IAY0520 5.0 2
2015S 149411IASB IAY0520 5.0 5
2015S 149439IASB IAY0520 5.0 3
2015S 149438IASB ISS0021 6.0 1
2015S 149380IASB ISS0021 6.0 1
2015S 149396IASB ISS0021 6.0 5
2015S 149430IASB ISS0021 6.0 4
2015S 149404IASB ISS0021 6.0 5
2015S 149417IASB ISS0021 6.0 4
2015S 149421IASB ISS0021 6.0 1
2015S 149384IASB ISS0021 6.0 5
2015S 149378IASB ISS0021 6.0 5
2015S 149410IASB ISS0021 6.0 3
2015S 149389IASB ISS0021 6.0 5
2015S 149406IASB ISS0021 6.0 0
2015S 149395IASB ISS0021 6.0 0
2015S 149434IASB ISS0021 6.0 5
2015S 149385IASB ISS0021 6.0 4
2015S 149425IASB ISS0021 6.0 4
2015S 149405IASB ISS0021 6.0 4
2015S 149401IASB ISS0021 6.0 5
2015S 149411IASB ISS0021 6.0 3
2015S 149439IASB ISS0021 6.0 1
2015S 149438IASB ITV0010 4.0 4
2015S 149380IASB ITV0010 4.0 3
2015S 149396IASB ITV0010 4.0 0
2015S 149430IASB ITV0010 4.0 2
2015S 149404IASB ITV0010 4.0 2
2015S 149417IASB ITV0010 4.0 3
2015S 149421IASB ITV0010 4.0 5
2015S 149384IASB ITV0010 4.0 5
2015S 149378IASB ITV0010 4.0 4
2015S 149410IASB ITV0010 4.0 4
2015S 149389IASB ITV0010 4.0 5
2015S 149406IASB ITV0010 4.0 5
2015S 149395IASB ITV0010 4.0 3
2015S 149434IASB ITV0010 4.0 5
2015S 149385IASB ITV0010 4.0 4
2015S 149425IASB ITV0010 4.0 0
2015S 149405IASB ITV0010 4.0 4
2015S 149401IASB ITV0010 4.0 5
2015S 149411IASB ITV0010 4.0 5
2015S 149439IASB ITV0010 4.0 5
2015S 149438IASB IED0150 5.0 2
2015S 149380IASB IED0150 5.0 1
2015S 149396IASB IED0150 5.0 0
2015S 149430IASB IED0150 5.0 1
2015S 149404IASB IED0150 5.0 5
2015S 149417IASB IED0150 5.0 5
2015S 149421IASB IED0150 5.0 5
2015S 149384IASB IED0150 5.0 4
2015S 149378IASB IED0150 5.0 5
2015S 149410IASB IED0150 5.0 5
2015S 149389IASB IED0150 5.0 1
2015S 149406IASB IED0150 5.0 3
2015S 149395IASB IED0150 5.0 4
2015S 149434IASB IED0150 5.0 4
2015S 149385IASB IED0150 5.0 1
2015S 149425IASB IED0150 5.0 4
2015S 149405IASB IED0150 5.0 2
2015S 149401IASB IED0150 5.0 3
2015S 149411IASB IED0150 5.0 4
2015S 149439IASB IED0150 5.0 3
2016K 149438IASB YFR0012 6.0 5
2016K 149380IASB YFR0012 6.0 4
2016K 149396IASB YFR0012 6.0 5
2016K 149430IASB YFR0012 6.0 0
2016K 149404IASB YFR0012 6.0 5
2016K 149417IASB YFR0012 6.0 5
2016K 149421IASB YFR0012 6.0 1
2016K 149384IASB YFR0012 6.0 4
2016K 149378IASB YFR0012 6.0 5
2016K 149410IASB YFR0012 6.0 4
2016K 149389IASB YFR0012 6.0 5
2016K 149406IASB YFR0012 6.0 4
2016K 149395IASB YFR0012 6.0 5
2016K 149434IASB YFR0012 6.0 4
2016K 149385IASB YFR0012 6.0 4
2016K 149425IASB YFR0012 6.0 1
2016K 149405IASB YFR0012 6.0 3
2016K 149401IASB YFR0012 6.0 3
2016K 149411IASB YFR0012 6.0 1
2016K 149439IASB YFR0012 6.0 5
2016K 149438IASB ISS0010 5.0 5
2016K 149380IASB ISS0010 5.0 4
2016K 149396IASB ISS0010 5.0 5
2016K 149430IASB ISS0010 5.0 0
2016K 149404IASB ISS0010 5.0 0
2016K 149417IASB ISS0010 5.0 4
2016K 149421IASB ISS0010 5.0 5
2016K 149384IASB ISS0010 5.0 5
2016K 149378IASB ISS0010 5.0 4
2016K 149410IASB ISS0010 5.0 5
2016K 149389IASB ISS0010 5.0 4
2016K 149406IASB ISS0010 5.0 1
2016K 149395IASB ISS0010 5.0 4
2016K 149434IASB ISS0010 5.0 0
2016K 149385IASB ISS0010 5.0 5
2016K 149425IASB ISS0010 5.0 1
2016K 149405IASB ISS0010 5.0 5
2016K 149401IASB ISS0010 5.0 4
2016K 149411IASB ISS0010 5.0 5
2016K 149439IASB ISS0010 5.0 5
2016K 149438IASB ISP0040 5.0 1
2016K 149380IASB ISP0040 5.0 4
2016K 149396IASB ISP0040 5.0 5
2016K 149430IASB ISP0040 5.0 2
2016K 149404IASB ISP0040 5.0 5
2016K 149417IASB ISP0040 5.0 1
2016K 149421IASB ISP0040 5.0 2
2016K 149384IASB ISP0040 5.0 5
2016K 149378IASB ISP0040 5.0 0
2016K 149410IASB ISP0040 5.0 3
2016K 149389IASB ISP0040 5.0 1
2016K 149406IASB ISP0040 5.0 5
2016K 149395IASB ISP0040 5.0 5
2016K 149434IASB ISP0040 5.0 5
2016K 149385IASB ISP0040 5.0 4
2016K 149425IASB ISP0040 5.0 3
2016K 149405IASB ISP0040 5.0 2
2016K 149401IASB ISP0040 5.0 5
2016K 149411IASB ISP0040 5.0 0
2016K 149439IASB ISP0040 5.0 5
2016K 149438IASB IAY0140 5.0 5
2016K 149380IASB IAY0140 5.0 3
2016K 149396IASB IAY0140 5.0 5
2016K 149430IASB IAY0140 5.0 2
2016K 149404IASB IAY0140 5.0 5
2016K 149417IASB IAY0140 5.0 4
2016K 149421IASB IAY0140 5.0 0
2016K 149384IASB IAY0140 5.0 2
2016K 149378IASB IAY0140 5.0 5
2016K 149410IASB IAY0140 5.0 5
2016K 149389IASB IAY0140 5.0 5
2016K 149406IASB IAY0140 5.0 5
2016K 149395IASB IAY0140 5.0 5
2016K 149434IASB IAY0140 5.0 5
2016K 149385IASB IAY0140 5.0 4
2016K 149425IASB IAY0140 5.0 4
2016K 149405IASB IAY0140 5.0 3
2016K 149401IASB IAY0140 5.0 4
2016K 149411IASB IAY0140 5.0 5
2016K 149439IASB IAY0140 5.0 5
2016K 149438IASB IXX1410 3.0 5
2016K 149380IASB IXX1410 3.0 5
2016K 149396IASB IXX1410 3.0 4
2016K 149430IASB IXX1410 3.0 4
2016K 149404IASB IXX1410 3.0 1
2016K 149417IASB IXX1410 3.0 1
2016K 149421IASB IXX1410 3.0 4
2016K 149384IASB IXX1410 3.0 4
2016K 149378IASB IXX1410 3.0 0
2016K 149410IASB IXX1410 3.0 5
2016K 149389IASB IXX1410 3.0 1
2016K 149406IASB IXX1410 3.0 1
2016K 149395IASB IXX1410 3.0 5
2016K 149434IASB IXX1410 3.0 1
2016K 149385IASB IXX1410 3.0 5
2016K 149425IASB IXX1410 3.0 4
2016K 149405IASB IXX1410 3.0 2
2016K 149401IASB IXX1410 3.0 5
2016K 149411IASB IXX1410 3.0 4
2016K 149439IASB IXX1410 3.0 4
2014S
G.BECKETT - 0.00
P.BOLDEN - 4.00
D.BRIGGS - 0.00
D.COX - 2.67
G.DENT - 5.00
B.ELMORE - 2.50
R.ESPINOSA - 3.94
S.GRAVES - 2.14
S.GRUBBS - 4.00
M.HOOD - 1.50
A.MALLORY - 5.00
M.MERRILL - 4.38
R.MOORE - 4.43
A.RODGERS - 5.00
P.SHIELDS - 4.31
E.THORNTON - 4.50
A.VARNEY - 2.52
K.WHITT - 3.76
C.WILBURN - 3.43
E.YOR - 2.24
2015K
G.BECKETT - 3.52
P.BOLDEN - 2.52
D.BRIGGS - 2.19
D.COX - 2.86
G.DENT - 3.24
B.ELMORE - 2.29
R.ESPINOSA - 4.76
S.GRAVES - 2.10
S.GRUBBS - 3.24
M.HOOD - 2.95
A.MALLORY - 4.24
M.MERRILL - 4.00
R.MOORE - 3.71
A.RODGERS - 4.52
P.SHIELDS - 2.62
E.THORNTON - 4.48
A.VARNEY - 4.29
K.WHITT - 4.76
C.WILBURN - 2.71
E.YOR - 2.62
2015S
G.BECKETT - 4.24
P.BOLDEN - 2.12
D.BRIGGS - 4.20
D.COX - 3.60
G.DENT - 4.00
B.ELMORE - 2.08
R.ESPINOSA - 2.80
S.GRAVES - 3.80
S.GRUBBS - 4.52
M.HOOD - 3.80
A.MALLORY - 3.20
M.MERRILL - 4.16
R.MOORE - 4.32
A.RODGERS - 4.24
P.SHIELDS - 3.84
E.THORNTON - 3.36
A.VARNEY - 2.08
K.WHITT - 3.80
C.WILBURN - 2.88
E.YOR - 2.84
2016K
G.BECKETT - 3.13
P.BOLDEN - 3.92
D.BRIGGS - 4.00
D.COX - 4.33
G.DENT - 3.46
B.ELMORE - 4.79
R.ESPINOSA - 4.88
S.GRAVES - 4.08
S.GRUBBS - 3.46
M.HOOD - 3.08
A.MALLORY - 3.42
M.MERRILL - 4.33
R.MOORE - 2.83
A.RODGERS - 3.25
P.SHIELDS - 2.21
E.THORNTON - 2.42
A.VARNEY - 1.33
K.WHITT - 3.21
C.WILBURN - 4.17
E.YOR - 4.88
149378IASB G.BECKETT
149380IASB P.BOLDEN
149384IASB D.BRIGGS
149385IASB D.COX
149389IASB G.DENT
149395IASB B.ELMORE
149396IASB R.ESPINOSA
149401IASB S.GRAVES
149404IASB S.GRUBBS
149405IASB M.HOOD
149406IASB A.MALLORY
149410IASB M.MERRILL
149411IASB R.MOORE
149417IASB A.RODGERS
149421IASB P.SHIELDS
149425IASB E.THORNTON
149430IASB A.VARNEY
149434IASB K.WHITT
149438IASB C.WILBURN
149439IASB E.YOR
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char kursus[6];
char kood[11];
char aine[8];
double EAP;
int hinne;
}grades;
typedef struct
{
char kood[11];
char nimi[255];
double KKH[4];
double koguhinne[4];
double koguained[4];
}stud;
void kaalutud(grades *n, stud *m, int, int);
grades *Readgrades(int*, char*);
stud *Readstudents(int*, char*);
void nullimine(stud *m, int);
void arvutus(stud *m, int);
void v2ljastus(stud *m, int);
int main(void)
{
int nrStud;
int nrGrades;
char File1Name[] = {"grades3.txt"};
char File2Name[] = {"stud.txt"};
grades *n=Readgrades(&nrGrades,File1Name);
stud *m=Readstudents(&nrStud,File2Name);
nullimine(m, nrStud);
kaalutud(n, m, nrGrades, nrStud);
arvutus(m, nrStud);
v2ljastus(m, nrStud);
free(n);
free(m);
return 0;
}
void kaalutud(grades *n, stud *m, int nrGrad, int nrStud)
{
int i = 0;
int j = 0;
int k = 0;
int kontroll = 0;
do
{
do
{
for(j=0;j<=nrStud;j++)
{
if(strcmp((n+i)->kood, (m+j)->kood) == 0)
{
(m+j)->koguhinne[k] += (n+i)->hinne * (n+i)->EAP;
(m+j)->koguained[k] += (n+i)->EAP;
nrGrad--;
break;
}
}
kontroll = strcmp((n+i)->kursus, (n+(i+1))->kursus);
i++;
}while(kontroll == 0);
k++;
}while(nrGrad != 0);
}
stud *Readstudents(int *Total, char *FileName)
{
int i=0;
stud buf;
stud *pTemp=NULL;
stud *pArr=NULL;
FILE *fi=fopen(FileName,"r");
if(fi==NULL)
{
exit(1);
}
while(fscanf(fi,"%s%s",buf.kood, buf.nimi)!=EOF)
{
pTemp=(stud*)realloc(pArr,sizeof(stud)*(i+1));
if( pTemp == NULL)
{
printf("Memory Allocation Failed");
fclose(fi);
free(pArr);
exit(1);
}
else
{
pArr=pTemp;
strcpy((pArr + i)-> kood,buf.kood);
strcpy((pArr + i)-> nimi,buf.nimi);
i++;
}
}
fclose(fi);
*Total=i;
return pArr;
}
grades *Readgrades(int *Total, char *FileName)
{
int i=0;
grades buf;
grades *pTemp=NULL;
grades *pArr=NULL;
FILE *fi=fopen(FileName,"r");
if(fi==NULL)
{
exit(1);
}
while(fscanf(fi,"%s%s%s%lf%d",buf.kursus, buf.kood, buf.aine, &buf.EAP, &buf.hinne)!=EOF)
{
pTemp=(grades*)realloc(pArr,sizeof(grades)*(i+1));
if( pTemp == NULL)
{
printf("Memory Allocation Failed");
fclose(fi);
free(pArr);
exit(1);
}
else
{
pArr=pTemp;
(pArr+i)->EAP=buf.EAP;
(pArr+i)->hinne=buf.hinne;
strcpy((pArr + i)-> kursus,buf.kursus);
strcpy((pArr + i)-> kood,buf.kood);
strcpy((pArr + i)-> aine,buf.aine);
i++;
}
}
fclose(fi);
*Total=i;
return pArr;
}
void nullimine(stud *m, int nrStud)
{
int i;
nrStud--;
while(nrStud != -1)
{
for(i = 0;i < 4; i++)
{
(m+nrStud)->KKH[i] = 0;
(m+nrStud)->koguained[i] = 0;
(m+nrStud)->koguhinne[i] = 0;
}
nrStud--;
}
}
void arvutus(stud *m, int nrStud)
{
int i;
int j;
for(i=0;i<nrStud;i++)
{
for(j=0;j<4;j++)
{
(m+i)->KKH[j] = (m+i)->koguhinne[j] / (m+i)->koguained[j];
if((m+i)->koguained[j] == 0)
{
(m+i)->KKH[j] = 0;
}
printf("%.2lf\n", (m+i)->KKH[j]);
}
}
}
void v2ljastus(stud *m, int nrStud)
{
int i;
int j;
int x = 0;
FILE* F = fopen("output.txt", "w");
for(j=0;j<4;j++)
{
fprintf(F, "\n20");
fprintf(F, "%d", 14+x);
if(j%2 == 0)
{
fprintf(F, "S\n\n");
x++;
} else
{
fprintf(F, "K\n\n");
}
for(i=0;i<nrStud;i++)
{
fprintf(F, "%s - %.2lf\n", (m+i)->nimi, (m+i)->KKH[j]);
}
}
}
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