#include "stdio.h"
#include "conio.h"
#define N 4
//float P[2][N] = {2, 1, -2, -1,
// 2, -2, 2, 0};
//float T[1][N] = {0, 1, 0, 1};
float P[2][N] = {0, 1, 0, 1,
0, 0, 1, 1};
float T[1][N] = {0, 0, 0, 1};
float E[1][1] = {0};
float W[1][2] = {0, 0};
float B[1][1] = {0};
float A[1][1] = {0};
float sign(float);
void GetA(int, int);
void GetW(int);
void GetB();
int ABS(float);
int main(void)
{
int i;
i = N;
int j;
j = 0;
int k;
k = 0;
while(i)
{
printf("********************\n");
GetA(j,k);
printf("a = :\n%.4f\n", A[0][0]);
E[0][0] = T[0][j] - A[0][0];
printf("e = :\n%.4f\n", E[0][0]);
GetW(j);
printf("w = :\n%.4f %.4f\n", W[0][0], W[0][1]);
GetB();
printf("b = :\n%.4f\n", B[0][0]);
j++;
if(j >= N)
{
j = 0;
}
k = j;
if((ABS(E[0][0]) == 0))
i --;
else
i = N;
}
printf("\nxunlian over! \n");
printf("Y start ceishi!\n");
while(getch() == 'y')
{
printf("\nenter ceshi: (1 3)\n");
float _a, _b;
scanf("%f%f",&_a,&_b);
printf("\njie guo is :%.4f\n",sign(_a*W[0][0]+_b*W[0][1]+B[0][0]));
printf("Y continue!\n");
}
return 0;
}
float sign(float a)
{
if(a >= 0)
return 1;
else
return 0;
}
void GetA(int j,int k)
{
int _i;
_i = 2;
float sum;
sum = 0;
for(_i = 0; _i<2; _i++)
{
sum += W[0][_i]*P[_i][k];
}
sum += B[0][0];
A[0][0] = sign(sum);
}
void GetW(int j)
{
int _i;
for(_i = 0; _i<2; _i++)
{
W[0][_i] += E[0][0]*P[_i][j];
}
}
void GetB()
{
B[0][0] += E[0][0];
}
int ABS(float a)
{
#define _E 0.00001
if((a < _E)&&(a >- _E))
return 0;
else
return 1;
}