Professional Documents
Culture Documents
raya
[sourcecode language='cpp']#include
#include
#include char matrix[3][3];//={0};
void cou(void);
int main()
{
int m,n;
char ch=y';
while(ch==Y'||ch==y')
{
for (m=0;m<3;m++)
for (n=0;n<3;n++)
matrix[m][n]= '';
int i,j,sum=0;
while ( sum < 10)
{
if (sum == 0)
cou();
cout<<"Player 1 is 'X': choose the row and column"<<endl;
cout<<"Row : ";
cin>>i;
cout<<"Column : ";
cin>>j;
for (;i>3 || i<1 || j>3 || j<1 ||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
cout<<"Sorry boy, but you gotta choose another place.n";
cout<<"row : ";
cin>>i;
cout<<"column : ";
cin>>j;
}
matrix[i-1][j-1]=X';
sum++;
cou();</endl;
//check if wins
if (matrix[0][0]==X && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{cout<<"Player 1 wins"<<endl;break;}
if (matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2])
{cout<<"Player 1 wins"<<endl;break;}
if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0])
{cout<<"Player 1 wins"<<endl;break;}
if (matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1])
{cout<<"Player 1 wins"<<endl;break;}
REGRESION LINEAL
#include<stdio.h>
#include<math.h>
int L;
int main(void){
double a, b;
int i;
L=5;
// Linea
regresion(tmp,L,&a,&b);
printf("Lineal: a=%.10f y b=%.4f\n", a, b);
// Curva potencial
for(i=0;i<L;i++){
tmp[i][0]=(double)log(pot[i][0]);
tmp[i][1]=(double)log(pot[i][1]);
}
regresion(tmp,L,&a,&b);
printf("Potencial: a=%.10f y b=%.4f\n", a, b);
//Curva logaritmica
for(i=0;i<L;i++){
tmp[i][0]=(double)log(loga[i][0]);
tmp[i][1]=loga[i][1];
}
regresion(tmp,L,&a,&b);
printf("Llogaritmica: a=%.10f y b=%.4f\n", a, b);
//Curva exponencial
for(i=0;i<L;i++){
tmp[i][0]=expo[i][0];
tmp[i][1]=(double)log(expo[i][1]);
}
regresion(tmp,L,&a,&b);
printf("Exponencial: a=%.10f y b=%.4f\n", a, b);
//
return 0;
}
//Regresion lineal
double regresion(double Tmp[5][2], int l,double *A, double *B){
int i;
double SumX,SumY,SumXX,SumXY,D;
for(i=0;i<l;i++){
SumX += Tmp[i][0];
SumY += Tmp[i][1];
SumXX += Tmp[i][0]*Tmp[i][0];
SumXY += Tmp[i][0]*Tmp[i][1];
}
D = l*SumXX-SumX*SumX;
*A = (SumXX*SumY-SumX*SumXY)/D;
*B = (l*SumXY-SumX*SumY)/D;
return *A,*B;
}