int main(int argc,char*argv[]){ double *A,*B,*C; int i,j,k; int check=1; double timetick; //Controla los argumentos al programa if ((argc != 2) || ((N = atoi(argv[1])) <= 0) ) { printf("\nUsar: %s n\n n: Dimension de la matriz (nxn X nxn)\n", argv[0]); exit(1); } //Aloca memoria para las matrices A=(double*)malloc(sizeof(double)*N*N); B=(double*)malloc(sizeof(double)*N*N); C=(double*)malloc(sizeof(double)*N*N); //Inicializa las matrices A y B en 1, el resultado sera una matriz con todos sus valores en N for(i=0;i<N;i++){ for(j=0;j<N;j++){ setValor(A,i,j,ORDENXFILAS,1); setValor(B,i,j,ORDENXFILAS,1); } } //Realiza la multiplicacion timetick = dwalltime(); for(i=0;i<N;i++){ for(j=0;j<N;j++){ setValor(C,i,j,ORDENXFILAS,0); for(k=0;k<N;k++){ setValor(C,i,j,ORDENXFILAS, getValor(C,i,j,ORDENXFILAS) + getValor(A,i,k,ORDENXFILAS)*getValor(B,k,j,ORDENXFILAS)); } } } printf("Tiempo en segundos %f\n", dwalltime() - timetick); //Verifica el resultado for(i=0;i<N;i++){ for(j=0;j<N;j++){ check=check&&(getValor(C,i,j,ORDENXFILAS)==N); } } if(check){ printf("Multiplicacion de matrices resultado correcto\n"); }else{ printf("Multiplicacion de matrices resultado erroneo\n"); } free(A); free(B); free(C); return(0); }
void setValorVariable(imagen_proceso_t proceso, char nombreVariable, int32_t valorVariable) { t_link_element* unaVariable = proceso.segmentoDeDatos->head; while(unaVariable != NULL && !esLaVariableQueBusco(unaVariable->data,nombreVariable)) unaVariable = unaVariable->next; if(unaVariable == NULL) return; setValor(unaVariable->data,valorVariable); }
void evaluar() { float nota = 0; int sumar(int a, int b); int restar(int a, int b); int multiplicar(int a, int b); int dividir(int a, int b); int getMayor(int a, int b); int getMenor(int a, int b); int getMayor(int a, int b, int c); void setValor(int arreglo[], int valor, int posicion); int getValor(int arreglo[], int posicion); int getMayor(int arreglo[], int tamano); int getMenor(int arreglo[], int tamano); int getPromedio(int arreglo[], int tamano); cout<<"Ejercicio sumar:\t\t"; if(sumar(5,3)==8 && sumar(2,1)==3 && sumar(1000,1234)==2234) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio restar:\t\t"; if(restar(5,3)==2 && restar(2,1)==1 && restar(5,7)==-2) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio multiplicar:\t\t"; if(multiplicar(5,3)==15 && multiplicar(2,1)==2 && multiplicar(5,-7)==-35) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio dividir:\t\t"; if(dividir(9,3)==3 && dividir(2,1)==2 && dividir(8,2)==4) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getMayor:\t\t"; if(getMayor(9,3)==9 && getMayor(1,2)==2 && getMayor(8,2)==8 && getMayor(8,16)==16) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getMenor:\t\t"; if(getMenor(9,3)==3 && getMenor(1,2)==1 && getMenor(8,2)==2 && getMenor(8,16)==8) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getMayor:\t\t"; if(getMayor(9,3,5)==9 && getMayor(1,3,2)==3 && getMayor(2,8,2)==8 && getMayor(8,5,16)==16) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio setValor:\t\t"; int arr[]={1,2,3}; setValor(arr,4,1); setValor(arr,9,2); int arr2[]={10,20}; setValor(arr2,30,1); if(arr[0]==1 && arr[1]==4 && arr[2]==9 && arr2[0]==10 && arr2[1]==30) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getValor:\t\t"; int a1[]={3,4,2,1}; int a2[]={10,20,30}; if(getValor(a1,0)==3 && getValor(a1,1)==4 && getValor(a2,0)==10 && getValor(a2,1)==20) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getMayor:\t\t"; if(getMayor(a1,4)==4 && getMayor(a2,3)==30) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getMenor:\t\t"; if(getMenor(a1,4)==1 && getMenor(a2,3)==10) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } cout<<"Ejercicio getPromedio:\t\t"; if(getPromedio && getPromedio(a2,3)==20) { nota+=0.5; cout<<"Correcto"<<endl; }else { cout<<"Incorrecto"<<endl; } int pl; cout<<endl<<"Nota: "<<nota<<"/6"<<endl; cin>>pl; }
CARTA::CARTA( int val=1, char nai='O', bool vis=false){ setValor(val); setNaipe(nai); visivel = vis; }
CARTA::CARTA(){ setValor(1); setNaipe('O'); visivel = false; }
Corona::Corona(string id, int i) :Elemento(id, i) { setValor((rand() % (MAX_VALOR - MIN_VALOR) + MIN_VALOR)); setGramos((rand() % (MAX_PESO - MIN_PESO) + MIN_PESO)); }