You are on page 1of 9

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

//OPERACIONES CON NUMEROS COMPLEJOS: SUMA, RESTA, MULTIPLICACION, DIVISION, //USANDO ARGUMENTOS POR REFERENCIA. #include <stdio.h> //#include <stdlib.h> int menu(); int datos_entrada(); int fsuma(int *sum1, int *sum2); int fresta1(int *rest1, int *rest2); int fresta2(int *rest2a, int *rest2b); int fmulti(int *mult1, int *mult2); int fdiv1(int *div1, int *div2); int fdiv2(int *div2a, int *div2b); struct complejos{ int a, b; }com1, com2, suma, resta, prod, div; main(){ int p,opcion; datos_entrada(); opcion=menu(); while (opcion!=5){ switch (opcion){ case 1: fsuma(&suma.a,&suma.b); printf("\n C[1] + C[2] = %d + %di ",suma.a,suma.b); return menu (); break; case 2: printf("\En que orden los quieres restar:\n1.- C[1] - C[2]: \n2.- C[2] - C[1]\n"); scanf("%d",&p); if (p==1){ fresta1(&resta.a,&resta.b); printf("\n C[1] - C[2] = %d + %di ",resta.a,resta.b); } else if (p==2){ fresta2(&resta.a,&resta.b); printf("\n C[2] - C[1] = %d + %d ",resta.a,resta.b); } return menu(); break;
LAB. PROGRAMACIN AVAN. Y MET. NUM. GRUPO 03 SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

case 3: fmulti(&prod.a,&prod.b); printf("\nC[1] x C[2] = %d + %di",prod.a,prod.b); return menu (); break; case 4: printf("\nEn que orden los quiere dividir?\n1.- C[1] / C[2]: \n2.- C[2] / C[1]\n"); scanf("%d",&p); if (p==1){ fdiv1(&div.a,&div.b); printf("\nC[1] / C[2] = %d + %di",div.a,div.b); } else if (p==2){ fdiv2(&div.a,&div.b); printf("\nC[2] / C[1] = %d + %di",div.a,div.b); } return menu(); break; default: printf("\nOpcion incorrecta. No existe esta operacion o estas jugando con la calculadora"); break; } } system("PAUSE"); } int menu(){ int opcion; printf("\n1. Suma. \n2. Resta. \n3. Multiplicacion. \n4. Division. "); printf("\nEscoge una opcion: \n"); scanf("%d",&opcion); return opcion; } int datos_entrada(){ printf("\nOperaciones con numeros complejos...\n\nForma c = a + bi"); printf("\nIntroduce C[1]a: "); scanf("%d",&com1.a); printf("Introduce C[1]b: "); scanf("%d",&com1.b); printf("\nIntroduce C[2]a: "); scanf("%d",&com2.a);
LAB. PROGRAMACIN AVAN. Y MET. NUM. GRUPO 03 SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

printf("Introduce C[2]b: "); scanf("%d",&com2.b); printf("\nC[1] = %d + %di",com1.a,com1.b); printf("\nC[2] = %d + %di \n",com2.a,com2.b); } int fsuma(int *sum1, int *sum2){ *sum1=com1.a+com2.a; *sum2=com1.b+com2.b; } int fresta1(int *rest11, int *rest21){ *rest11=com1.a-com2.a; *rest21=com1.b-com2.b; } int fresta2(int *rest2a, int *rest2b){ *rest2a=com2.a-com1.a; *rest2b=com2.b-com1.b; } int fmulti(int *mult1, int *mult2){ *mult1=(com1.a*com2.a)-(com1.b*com2.b); *mult2=(com2.a*com1.b)+(com1.a*com2.b); } int fdiv1(int *div1, int *div2){ *div1=((com1.a*com2.a)+(com1.b*com2.b))/((com2.a*com2.a)+(com2.b*com2.b)); *div2=((com1.b*com2.a)-(com1.a*com2.b))/((com2.a*com2.a)+(com2.b*com2.b)); } int fdiv2(int *div2a, int *div2b){ *div2a=((com2.a*com1.a)+(com2.b*com1.b))/((com1.a*com1.a)+(com1.b*com1.b)); *div2b=((com2.b*com1.a)-(com2.a*com1.b))/((com1.a*com1.a)+(com1.b*com1.b)); }

LAB. PROGRAMACIN AVAN. Y MET. NUM.

GRUPO 03

SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

LAB. PROGRAMACIN AVAN. Y MET. NUM.

GRUPO 03

SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

LAB. PROGRAMACIN AVAN. Y MET. NUM.

GRUPO 03

SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

//CALCULADORA DE MATRICES USANDO FUNCION MALLOC (MEMORIA DINMICA). #include <stdio.h> #include <stdlib.h> main(){ int **ap,**ap1,**ap2,i,n,j,k; //**ap es un apuntador de apuntadores int opcion; printf("de que tamano son tus arreglos?"); scanf("%d",&n); ap=(int**)malloc(n*sizeof(int*)); for(i=0;i<n;i++) //usamos un for para la memoria dinamica del apuntador de apuntadores ap[i]=(int*)malloc(n*sizeof(int)); ap1=(int**)malloc(n*sizeof(int)); for(i=0;i<n;i++) //usamos un for para la memoria dinamica del apuntador de apuntadores ap1[i]=(int*)malloc(n*sizeof(int)); printf("\nDame la matriz A: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("Dame el elemento a[%i][%i]",i,j); scanf("%d",&ap[i][j]); } } printf("\nLa matriz [1] es: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("\t %d",ap[i][j]); } printf("\n"); }//for(i=1;i<=n;i++) //usamos un for para la memoria dinamica del apuntador de apuntadores //ap[i]=(int*)malloc(n*sizeof(int)); printf("\nDame la matriz B: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("Dame el elemento b[%i][%i]",i,j); scanf("%d",&ap1[i][j]); } } printf("\nLa matriz B es: \n"); for(i=0;i<n;i++){
LAB. PROGRAMACIN AVAN. Y MET. NUM. GRUPO 03 SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

for(j=0;j<n;j++){ printf("\t %d",ap1[i][j]); } printf("\n"); } printf("\nLas operaciones con matrices son: \n"); printf("\n1.- Suma\n2.- Resta\n3.- Transpuesta\n4.- Multiplicacion \nEscoge opcion: \n"); scanf("%d",&opcion); switch (opcion){ case 1: printf("\nLa matriz suma es: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("\t %d",ap[i][j]+ap1[i][j]); } printf("\n"); } break; case 2: printf("\nLa matriz resta es: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("\t %d",ap[i][j]-ap1[i][j]); } printf("\n"); } break; case 3: printf("\nLa matriz transpuesta de A es: \n"); for(j=0;j<n;j++){ for(i=0;i<n;i++){ printf("\t %d",ap[i][j]); } printf("\n"); } printf("\nLa matriz transpuesta de B es: \n"); for(j=0;j<n;j++){ for(i=0;i<n;i++){ printf("\t %d",ap1[i][j]); }
LAB. PROGRAMACIN AVAN. Y MET. NUM. GRUPO 03 SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

printf("\n"); } break; case 4: ap2=(int**)malloc(n*sizeof(int*)); for(i=0;i<n;i++) //usamos un for para la memoria dinamica del apuntador de apuntadores ap2[i]=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++){ for(j=0;j<n;j++){ ap2[i][j]=0; for(k=0;k<n;k++){ ap2[i][j]=(ap2[i][j]+(ap[i][k]*ap1[k][j])); } } } printf("\nLa matriz A x B es: \n"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("\t %d",ap2[i][j]); } printf("\n"); } } for(i=0;i<n;i++){ free(ap[i]); free(ap); //} for(i=0;i<n;i++)//{ free(ap1[i]); free(ap1); } system("pause"); }

LAB. PROGRAMACIN AVAN. Y MET. NUM.

GRUPO 03

SEM 2013 - I

SOLANO GUZMN CARLOS JAVIER

PRCTICA 3 Y 2

11 / SEP / 2012

MULTIPLICACIN

LAB. PROGRAMACIN AVAN. Y MET. NUM.

GRUPO 03

SEM 2013 - I

You might also like