You are on page 1of 7

//suma y resta de vectores

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void captura(int[],int);
void suma(int[],int[],int);
void resta(int[],int[],int);
int c;
main()
{
char r;
int n,v1[c],v2[c],v3[c];
do{
system("cls");
printf("\n Introduce la cantidad de elementos de los vectores 2 si x,y o 3 si x,y,z:\n");
scanf("%d",&n);
if(n<=1||n>=4)
{
printf("\n Solo se acepta 2 o 3\n\n\n\n\t");
system ("pause");
}
}while(n<=1||n>=4);
printf("\n Captura del primer vector");
captura(v1,n);
printf("\n Captura del segundo vector");
captura(v2,n);
printf("\n Suma de vectores es");
suma(v1,v2,n);
printf("\n Resta de de vectores es");
resta(v1,v2,n);
system("pause");

}
void captura(int v[],int n)
{
for(c=1;c<=n;c++)
{ printf("\n[%d]= ",c);
scanf("%d",&v[c]);
}
}
void suma(int v1[],int v2[],int n)
{
int v3[c];
for(c=1;c<=n;c++)
{
v3[c]=v1[c]+v2[c];
printf("\n %d",v3[c]);
}
}
void resta(int v1[],int v2[],int n)
{
int v3[c];
for(c=1;c<=n;c++)
{
v3[c]=v2[c]-v1[c];
printf("\n %d",v3[c]);

}
}
//producto punto, magnitud y angulo
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
float porp(float[], float [], float, int);
float magnitud(float [], int);
float angulo(float, float, float);
void captura(float [], int);
void datos(void);
int c;
main()
{printf("\n\t Programa de producto punto, magnitud y angulo de vectores");
datos();
system("pause");
}
void datos(void)
{int n;
float V1[c], V2[c], pp, m1, m2, ang;
do{
printf("\n\t Elija las dimensiones de su plano: 2 para XY o 3 para XYZ\n\n\t");
scanf("%d",&n);
if (n<2 || n>3)
{printf("\n\t Se acepta el 2 o 3");
}
}while (n<2 || n>3);
printf("\n\t Poner el valor de V1");
captura(V1,n);
printf("\n\t Poner el valor de V2");
captura(V2,n);
system("cls");
pp=porp(V1, V2, pp, n);
m1=magnitud(V1,n);
m2= magnitud (V2,n);
ang= angulo(pp, m1, m2);
printf("\n\n\n\t\n\n\n\t El valor del producto punto de los vectores es: %f", pp);
printf("\n\n\t La magnitud del 1er vector es: %f", m1);
printf("\n\n\t La magnitud del 2do vector es: %f", m2);
printf("\n\n\t El valor del angulo entre los vectores es %f", ang);

}
void captura(float V[], int n)
{
char e;
for(c=1,e='x';c<=n;c++,e++)
{
printf("\n\t V[%c]= ",e);
scanf("%f",&V[c]);
}
}
float porp(float V1[], float V2[], float pp, int n)
{
pp=0;
for (c=1;c<=n;c++)
{
pp=pp+(V1[c]*V2[c]);
}
return pp;
}
float magnitud(float V[], int n)
{
float m=0;
for (c=1;c<=n;c++)
{
m=m+pow(V[c],2);
}
return sqrt(m);
}
float angulo(float pp, float m1, float m2)
{
double a;
a=acos(pp/m1*m2);
return a;
}
//distancia entre vectores
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
float dp(float[], float [], float, int);
void captura(float [], int);
void datos(void);
int c;
main()
{printf("\n\t\t Programa de distancia entre vectores \n\n");
datos();
system("pause");
}
void datos(void)
{
char r;
int n;
float V1[c], V2[c], pp;
do{
do{
printf("\n\t *Elija las dimensiones de su plano: 2 para XY o 3 para XYZ*\n\n\t");
scanf("%d",&n);
if (n<2 || n>3)
{printf("\n\t ****Solo se acepta 2 para XY o 3 para XYZ****");
}
}while (n<2 || n>3);
printf("\n\t *Poner el valor de* V1º");
captura(V1,n);
printf("\n\t *Poner el valor de V2*");
captura(V2,n);
system("cls");
pp=dp(V1, V2, pp, n);
printf("\n\n\n\t\n\n\n\t El valor de la distancia entre vectores: %f\n\n\n", pp);
printf("\n\n\n\n Presiona ENTER para repetir o cualquier otra tecla para
salir ");
r=getch();
system("cls");

}while(r==13);
}
void captura(float V[], int n)
{
char e;
for(c=1,e='x';c<=n;c++,e++)
{
printf("\n\t V[%c]= ",e);
scanf("%f",&V[c]);
}
}
float dp(float V1[], float V2[], float pp, int n)
{
pp=0;
for (c=1;c<=n;c++)
{
pp=pp+(pow(V2[c]-V1[c],2));
}
return sqrt(pp);
}
//matriz transpuesta
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void datos(void);
int f,c;
main()
{

printf ("\n\t\ PROGRAMA QUE IMPRIME MATRIZ TRANSPUESTA \n\n");


datos();
system("pause");
}
void datos(void)
{
int M1[10][10],nf,nc;
printf("\n\n Ingrese numero de filas: ");
scanf("%d",&nf);
printf("\n Ingrese numero de columnas: ");
scanf("%d",&nc);
printf("\n Ingrese la matriz 1:\n");
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
printf("[%d,%d]= ",f,c);
scanf("%d",&M1[f][c]);
}
}

printf("\n lA MATRIZ ORIGINAL ES: \n");


for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
printf("%d " , M1[f][c]);
}
printf("\n");
}
printf("\n lA MATRIZ TRANSPUESTA ES: \n");
for(f=1;f<=nc;f++)
{
for(c=1;c<=nf;c++)
{
printf("%d " , M1[c][f]);
}
printf("\n");
}
}
//esczlar y promedio
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
float prom(int[][10],int,int);
void escalar(int[][10],int,int);
void captura(int[][10],int,int);
void datos(void);
int f,c;
main()
{

printf ("\n\t\ PROGRAMA QUE CALCULA PROMEDIO DE LOS VALORES DE


UNA MATRIZ \n\n");
datos();
system("pause");
}
void datos(void)
{
int M1[10][10],nf,nc,m;
printf("\n\n Ingrese numero de filas: ");
scanf("%d",&nf);
printf("\n Ingrese numero de columnas: ");
scanf("%d",&nc);
printf("\n Ingrese la matriz 1:\n");
captura(M1,nf,nc);
printf("\n Elige la opcion que quieras ");
printf("\n 1 Promedio \n 2 Escalar \n 3 SALIR\n\n\n ");
scanf("%d",&m);
if(m==1)printf("\n\n El promedio es: %.2f\n\n",prom (M1,nf,nc));
if(m==2)escalar (M1,nf,nc);
if(m==3)exit(0);
}
void captura(int M[][10],int nf,int nc)
{
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
printf("[%d,%d]= ",f,c);
scanf("%d",&M[f][c]);
}
}
}
float prom (int M1[][10],int nf,int nc)
{
int st=0, promedio;
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
st=st+M1[f][c];
}
}
promedio=st/(nf*nc);
return promedio;
}
void escalar(int M1[][10],int nf,int nc)
{
int Pr[10][10],e;
printf("\n Ingrese el valor a multiplicar\n\n");
scanf("%d",&e);
printf("\n El producto es: \n");
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
Pr[f][c]=M1[f][c]*e;
printf("%d " , Pr[f][c]);
}
printf("\n");
}
printf("\n El producto transpuesto es : \n");
for(f=1;f<=nc;f++)
{
for(c=1;c<=nf;c++)
{
Pr[f][c]=M1[nc][nf]*e;
printf("%d " , Pr[c][f]);
}
printf("\n");
}
}
//suma y resta de matrices
#include<stdlib.h>
#include<stdio.h>
void suma(int [][10], int [][10],int,int);
void resta(int [][10], int [][10],int,int);
void captura(int[][10],int,int);
void datos(void);
int f,c;
main()
{
printf("\n\t Programa que hace suma y resta de 2 matrices\n\n\n");
datos();
system("pause");
}
void datos (void)
{
int M1[10][10],nf,nc,M2[10][10],m;
printf("\n ingresa numero de filas ");
scanf("%d",&nf);
printf("\n ingresa numero de columnas ");
scanf("%d",&nc);
printf("\n ingresa la primer matriz\n");
captura(M1,nf,nc);
printf("\n ingresa la segunda matriz\n");
captura(M2,nf,nc);
printf("\n Elige la Operacion\n\n ");
printf("\n\t 1 Suma\n\n\t 2 Resta \n\n\t 3 Salir\n\n\n");
scanf("%d",&m);
if(m==1) suma (M1,M2,nf,nc);
if(m==2) resta (M1,M2,nf,nc);
if(m==3) exit (0);
}
void captura(int M[][10],int nf, int nc)
{
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
printf("[%d,%d]= ",f,c);
scanf("%d",&M[f][c]);
}
}
}
void suma(int M1[][10],int M2[][10],int nf, int nc)
{
int M3[10][10];
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
M3[f][c]=M1[f][c]+M2[f][c];
printf("%d", M3[f][c]);
}

{
printf("\n");
}
}
}
void resta(int M1[][10],int M2[][10],int nf, int nc)
{
int M3[10][10];
printf("\n La resta es\n\n");
for(f=1;f<=nf;f++)
{
for(c=1;c<=nc;c++)
{
M3[f][c]=M2[f][c]-M1[f][c];
printf("%d", M3[f][c]);
}

{
printf("\n");
}
}
printf("\n La resta transpuesta es\n\n");
for(f=1;f<=nc;f++)
{
for(c=1;c<=nf;c++)
{
M3[c][f]=M2[c][f]-M1[c][f];
printf("%d", M3[c][f]);
}

{
printf("\n");
}
}
}

You might also like