Projekt pierwszy,
WDP lab.
Adrian Białożyt GR 11
Kod źródłowy :
#include<stdio.h>
#include<math.h>
double ss(double x,double eps,int debugX){
double w,ret;
double pom;
ret = 0;
pom = (1/2.0)*x;
w = -((1/2.0)*x);
while( fabs(w) >= eps){
if(debugX == 1){
printf("=============\n");
printf("W = %lf \n",-w);
printf("RET + W = %lf \n",(ret+(-w)));
}
w = - w;
ret = ret+w;
w = w*pom;
}
return 1+ret;
}
void main( int argc, char *argv[] ){
double x,eps, s, spr;
FILE *dane, *wyniki;
int debugX = 0;
if ( (argc > 1) && (strcmp(argv[1],"debug") == 0)) {
printf("Debug ON params : %s\n",argv[1]);
debugX = 1;
}
dane = fopen("dane", "r");
wyniki = fopen("wyniki", "w");
if(dane!=NULL && wyniki!=NULL) {
fscanf(dane, "%lf %lf", &x, &eps);
printf("Dane:\nx = %lf\neps = %lf\n", x, eps);
fprintf(wyniki, "Dane:\nx = %lf\neps = %lf\n", x, eps);
s = ss(x,eps,debugX);
spr = pow((1+x), 0.5);
printf("\nSzukane:\nsuma = %lf\nspr = %lf", s, spr);
fprintf(wyniki, "\nSzukane:\nsuma = %lf\nspr = %lf", s, spr);
}
}
Informacje : Kod źródłowy został skompilowany przy pomocy GNU GCC Compiler z poziomu IDE
CODE:BLOCKS 10.05 w środowisku Windows 7 Ultimate x64.
Wynik budowania :
||=== Build finished: 0 errors, 0 warnings ===||
Wyniki testowe :
Dane:
x = -1.000000
eps = 0.010000
Szukane:
suma = 0.015625
spr = 0.000000
=====
Dane:
x = -0.800000
eps = 0.010000
Szukane:
suma = 0.340160
spr = 0.447214
=====
Dane:
x = -0.600000
eps = 0.010000
Szukane:
suma = 0.583000
spr = 0.632456
=====
Dane:
x = -0.400000
eps = 0.010000
Szukane:
suma = 0.760000
spr = 0.774597
=====
Dane:
x = -0.200000
eps = 0.010000
Szukane:
suma = 0.890000
spr = 0.894427
=====
Dane:
x = 0.000000
eps = 0.010000
Szukane:
suma = 1.000000
spr = 1.000000
=====
Dane:
x = 0.200000
eps = 0.010000
Szukane:
suma = 1.100000
spr = 1.095445
=====
Dane:
x = 0.400000
eps = 0.010000
Szukane:
suma = 1.160000
spr = 1.183216
=====
Dane:
x = 0.600000
eps = 0.010000
Szukane:
suma = 1.237000
spr = 1.264911
=====
Dane:
x = 0.800000
eps = 0.010000
Szukane:
suma = 1.288640
spr = 1.341641
=====
Dane:
x = 1.000000
eps = 0.010000
Szukane:
suma = 1.328125
spr = 1.414214
=====