Programa De Vectores Y Uno De Matrices

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Programa De Vectores Y Uno De Matrices as PDF for free.

More details

  • Words: 175
  • Pages: 2
// Ejemplo de vectores #include using namespace std; class Vector { public: float x, y; Vector operator+ (Vector v) { // función-operador operator+ x = x + v.x; y = y + v.y; return *this; } }; int main(){ // ========= float x = 5, y = 6; cout << "R = " << x + y << endl; // M.2: versión global Vector v1 = {1, 2}, v2 = {3, 4}; Vector v3 = v1 + v2; // M.4: versión sobrecargada cout << "Rx = " << v3.x << endl; cout << "Ry = " << v3.y << endl; }

//multiplicación de matrices #include<stdio.h> #include void main(void) { float m1[3][3],m2[3][3],ms[3][3]; int i,j; printf("Programa de suma de matrices\n"); printf("\n\n"); printf("Primera matriz:\n"); getch(); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("m1[%d][%d]=",i,j); scanf("%f",&m1[i][j]);

}

}

printf("\n Segunda matriz:\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("m2[%d][%d]=",i,j); scanf("%f", &m2[i][j]); } }

/*Paso 2 Calcular la multiplicacion*/

for(i=0;i<3;i++) for(j=0;j<3;j++) ms[i][j]=((m1[i][j])*(m2[i][j])); printf("\n Resultado:\n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%5.1f",m1[i][j]); if(i!=1) printf(" "); else printf("+"); for(j=0;j<3;j++) printf("%5.1f",m2[i][j]); if(i!=1) printf(" "); else printf("="); for(j=0;j<3;j++) printf("%5.1f",ms[i][j]); printf("\n"); } getch(); }

Related Documents