Funciones Del Programador

12
#include <iostream.h> #include <iomanip.h> #include <stdlib.h> #include <math.h> int main() { int x1, y1, x2, y2; double pendiente, b; cout << setw( 5 ) << "A(x,y)" << setw( 5 ) << "B(x,y)" << setw( 15 ) << "Ecuacion de Recta" << endl; randomize (); for ( int k=1; k<=8; k++ ) { x1= rand()%6; y1= rand()%6; x2= rand()%6; y2= rand()%6; if ( x1==x2 )

Transcript of Funciones Del Programador

Page 1: Funciones Del Programador

#include <iostream.h>

#include <iomanip.h>

#include <stdlib.h>

#include <math.h>

int main()

{

int x1, y1, x2, y2;

double pendiente, b;

cout << setw( 5 ) << "A(x,y)" << setw( 5 ) << "B(x,y)" << setw( 15 ) << "Ecuacion de Recta" << endl;

randomize ();

for ( int k=1; k<=8; k++ )

{

x1= rand()%6;

y1= rand()%6;

x2= rand()%6;

y2= rand()%6;

if ( x1==x2 )

{

cout << setw( 5 ) << "(" << x1 << "," << y1 << ")" << setw ( 6 ) << "(" << x2 << "," << y2 << ")" << setw ( 15 ) << "PENDIENTE INDEFINIDA" << endl;

Page 2: Funciones Del Programador

}

else

{

pendiente=(y2-y1)/(x2-x1);

b=y1-pendiente*x1;

if ( b>0)

{

cout << setw( 5 ) << "(" << x1 << "," << y1 << ")" << setw ( 6 ) << "(" << x2 << "," << y2 << ")" << setw ( 15 ) << "y=" << pendiente << "x+" << b << endl;

}

else

{

cout << setw( 5 ) << "(" << x1 << "," << y1 << ")" << setw ( 6 ) << "(" << x2 << "," << y2 << ")" << setw ( 15 ) << "y=" << pendiente << "x-" << fabs( b ) << endl;

}

}

}

return 0;

}

#include <iostream.h>

#include <iomanip.h>

#include <math.h>

Page 3: Funciones Del Programador

double raizcuadrada ( double z );

int main ()

{

double A, B, C;

cout << "Ingrese valor inicial:";

cin >> A;

cout << "Ingrese valor final";

cin>> B;

cout << "Ingrese valor para el incremento";

cin >> C;

cout << setw( 5 ) << "x" << setw( 15 ) << "f(x)" << endl;

for ( double x=A; x<=B; x=x+C )

if ( x*x+x-6<0 )

{

cout << setw( 5 ) << x << setw( 15 ) << "Indefinida" << endl;

}

else

{

cout << setw( 5 ) << x << setw( 15 ) << raizcuadrada ( x ) << endl;

Page 4: Funciones Del Programador

}

return 0;

}

double raizcuadrada ( double z )

{

return sqrt( z*z-z-6 );

}

#include <iostream.h>

#include <math.h>

double Paralelogramo( double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3);

int main()

{

double x1, x2, x3, y1, y2, y3, z1, z2, z3;

cout << "Ingrese la coordenada x del primer punto: ";

cin >> x1;

cout << "Ingrese la coordenada y del primer punto: ";

cin >> y1;

Page 5: Funciones Del Programador

cout << "Ingrese la coordenada z del primer punto: ";

cin >> z1;

cout << "Ingrese la coordenada x del segundo punto: ";

cin >> x2;

cout << "Ingrese la coordenada y del segundo punto: ";

cin >> y2;

cout << "Ingrese la coordenada z del segundo punto: ";

cin >> z2;

cout << "Ingrese la coordenada x del tercer punto: ";

cin >> x3;

cout << "Ingrese la coordenada y del tercer punto: ";

cin >> y3;

cout << "Ingrese la coordenada z del primer punto: ";

cin >> z3;

{

Paralelogramo( x1, x2, x3, y1, y2, y3, z1, z2, z3); }

return 0;

Page 6: Funciones Del Programador

}

// Funcion del Programador

double Paralelogramo( double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)

{

double magnitud1, magnitud2, area, angulo, r, s, t;

r=((b2-b1)*(c3-c1))-((c2-c1)*(b3-b1));

s=((a2-a1)*(c3-c1))-((c2-c1)*(a3-a1));

t=((a2-a1)*(b3-b1))-((a3-a1)*(b2-b1));

magnitud1=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)+(c2-c1)*(c2-c1));

magnitud2=sqrt((a3-a1)*(a3-a1)+(b3-b1)*(b3-b1)+(c3-c1)*(c3-c1));

area=sqrt(r*r+s*s+t*t);

angulo=asin(area/(magnitud1*magnitud2));

cout << "El producto cruz es: " << r << "i+(" << s << ")j+(" << t << ")K" << endl;

cout << "Magnitud de vector 1:" << magnitud1 << endl;

cout << "Magnitud de vector 2:" << magnitud2 << endl;

cout << " Area del paralelogramo" << area << endl;

cout << "Angulo entre vectores" << angulo*180/3.1416 << "grados" << endl;

Page 7: Funciones Del Programador

}

#include <iostream.h>

#include <math.h>

#include <stdlib.h>

double distanciaRectilinea( double a1, double a2, double b1, double b2, double c1, double c2);

int main()

{

double x1, x2, y1, y2, z1, z2;

randomize ();

x1=-10+rand()%21;

x2=-10+rand()%21;

y1=-10+rand()%21;

y2=-10+rand()%21;

z1=-10+rand()%21;

z2=-10+rand()%21;

{

distanciaRectilinea( x1, x2, y1, y2, z1, z2 );

}

Page 8: Funciones Del Programador

return 0;

}

double distanciaRectilinea( double a1, double a2, double b1, double b2, double c1, double c2)

{

double d;

d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)+(c2-c1)*(c2-c1));

cout << "Coordenadas punto 1: (" << a1 << "," << b1 << "," << c1 << ")" << endl;

cout << "Coordenadas punto 2: (" << a2 << "," << b2 << "," << c2 << ")" << endl;

cout << "La distancia entre los puntos es: " << d;

}

#include <iostream.h>

double factorial(int valor);

int j=1;

int main(){ int numero;

cout << "Introduzca un numero" << endl; cin >> numero; cout << endl;

cout << numero << "! es igual a: " << factorial(numero) << endl;

cout << "Se llamo a la funcion factorial " << j << " veces" << endl;

return 0;

Page 9: Funciones Del Programador

}

double factorial(int valor){ double resultado;

if(valor<=1) return 1; else { resultado = (valor*factorial(valor-1)); j = j+1; }

return resultado;}

#include <iostream.h>

int Recta(int x1, int y1, int z1, int x2, int y2, int z2 );

int main()

{

int a1, b1, c1, a2, b2, c2;

cout << "Ingrese la constante a1: " << endl;

cin >> a1;

cout << "Ingrese la constante b1: " << endl;

cin >> b1;

cout << "Ingrese la constante c1: " << endl;

cin >> c1;

Page 10: Funciones Del Programador

cout << "Ingrese la constante a2: " << endl;

cin >> a2;

cout << "Ingrese la constante b2: " << endl;

cin >> b2;

cout << "Ingrese la constante c2: " << endl;

cin >> c2;

{ Recta( a1, b1, c1, a2, b2, c2); }

return 0;

}

// Funcion del Programador

int Recta( int x1, int y1, int z1, int x2, int y2, int z2 )

{ int x, y;

if( x1*y2-x2*y1==0 && (z1/z2)==(x1/x2)&& (x1/x2)==(y1/y2))

{ cout << "Las rectas son iguales, el sistema tiene infinitas soluciones." << endl;

}

else

{ if( x1*y2-x2*y1==0 && z1/z2==!x1/x2)

Page 11: Funciones Del Programador

{ cout << "Las rectas son paralelas (no coinciden). Sistema incompatible (no tiene solucion)" << endl;

}

else

{ x=(y1*z2-z1*y2)/(x1*z2-x2*z1);

y=(x1*y2-x2*y1)/(x1*z2-x2*z1);

cout << "Solucion x: " << x << endl;

cout << "Solucion y: " << y << endl;

}

}

}