I have a problem here. I have two functions. One leads to x a(), the other to y, b(). I have y^2 in the functions to make it more apparent. They are reciprocal of each other. All I need is a couple lines, one, maybe two amd possibly three to complete my program. Ws won't change when it goes into T(). As you see I have it reassigning in the final for loop. Unfortunately it's not respecting me right now :-P. What am I missing that is stopping this from changing? It's a compression routine that holds digits in a smaller container, like the ladder in the garage paradox, the user doesn't see this unless he goes and looks at the compressed file. But maybe 100 characters can fit in a float number when going these functions. Please help me with my program. Thank you.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
constexpr float a(float y) { return 2*y/1024; }
constexpr float b(float y) { return 1024*y/2; }
constexpr int T(float x) {
for (int y=0;y<=255;y++)
if (b(x/(y*y))==x*a(y))
return y;
return 0;
}
int main() {
int l,i;
float Si[10] = { 30,10,20,15,35,47,18,3,5};
float Ts=0, Ts1=0, Ts4=0, Ws=1, W=0;
int Ts2=0, Ts3=0;
for (i=1;i<=9;i++) {
Ws=a(Si[i-1]*Si[i-1]*Ws);
printf("%f == %f \n", Si[i-1],Ws);
}
printf("\n");
for (int i=9;i>=1;i--) {
int x=T(Ws);
Ws=b(Ws/(x*x)); // right here, *** why doesn't Ws change?
printf("%d %f \n",x, Ws);
}
return 0;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire