Example #1
0
File: tp0.c Project: jpbrum2000/tp0
void kronecker(FILE *arquivo_input, FILE *arquivo_output)
{

    int pares_de_matrizes;

    fscanf(arquivo_input, "%d", &pares_de_matrizes);
    fprintf(arquivo_output, "%d\n", pares_de_matrizes);

    int lin_mat1, col_mat1, lin_mat2, col_mat2;
    int **matriz_um, **matriz_dois, **matriz_result;

    int par_itr;

    for (par_itr = 0; par_itr<pares_de_matrizes; par_itr++ )
    {
        //cria matriz_um
        fscanf(arquivo_input, "%d", &lin_mat1);
        fscanf(arquivo_input, "%d", &col_mat1);

        //preenche matriz 1
        matriz_um = preenche(arquivo_input, lin_mat1, col_mat1);

        //cria matriz_dois
        fscanf(arquivo_input, "%d", &lin_mat2);
        fscanf(arquivo_input, "%d", &col_mat2);
        //aloca matriz 2
        matriz_dois = preenche(arquivo_input, lin_mat2, col_mat2);

        //calculo matematico kronecker
        fprintf(arquivo_output, "%d", lin_mat1*lin_mat2);
        fprintf(arquivo_output, " %d\n", col_mat1*col_mat2);
        matriz_result = calcula_kronecker(matriz_um, lin_mat1, col_mat1, matriz_dois, lin_mat2, col_mat2);


        save_file(arquivo_output, lin_mat1*lin_mat2, col_mat1*col_mat2, matriz_result);



        int i;
        for (i=0; i<lin_mat1; i++) {
            free(matriz_um[i]);
        }
        free(matriz_um);

        for (i=0; i<lin_mat2; i++) {
            free(matriz_dois[i]);
        }
        free(matriz_dois);

        for (i=0; i<lin_mat1*lin_mat2; i++) {
            free(matriz_result[i]);
        }
        free(matriz_result);
    }


}
int main( int argc, char *argv[ ] ){
		
		//variaveis de tempo
		struct timeb start, stop;
		double elapsed;


		int i;
		if (argc > 1 ) {
			dimensao = atoi(argv[1]);
		}
		else {
			printf("\nQual a dimensao N (NxN) de suas matrizes?\n");
			scanf("%i",&dimensao);
		}



		//Cria matrizes 
		if (dimensao<=0 ) return -1;
		matrizA = (int **)malloc(dimensao*sizeof(int *));
		matrizB = (int **)malloc(dimensao*sizeof(int *));
		matrizResultado = (int **)malloc(dimensao*sizeof(int *));
		for (i=0;i<dimensao;i++) matrizA[i] = (int *)malloc(dimensao*sizeof(int));
		for (i=0;i<dimensao;i++) matrizB[i] = (int *)malloc(dimensao*sizeof(int));
		for (i=0;i<dimensao;i++) matrizResultado[i] = (int *)malloc(dimensao*sizeof(int));


		//PREENCHE MATRIZ 
		preenche(matrizA,time(NULL));
		preenche(matrizB,time(NULL)+1);
		
		//THREADS CALCULAM A MULTIPLICACAO
		ftime(&start);					//inicia timer
		multiplica(matrizA,matrizB);
		ftime(&stop);					//para timer
		elapsed=((double) stop.time + ((double) stop.millitm * 0.001)) - ((double) start.time + ((double) start.millitm * 0.001));
		
		//IMPRIME
		printf ("\nMatriz A:");
		imprime(matrizA);
		printf ("\nMatriz B:");
		imprime(matrizB);
		printf ("\n-Resultado:");
		imprime(matrizResultado);
		
		//gera link
		gerasite(matrizA,matrizB);
		
		printf("\n[1 arquivo  e Subprocessos =%i]  Matrizes = %i x %i -> O tempo de execucao e de %.3lf\n",dimensao, dimensao, dimensao,elapsed);

		//exit(0);
		return 0;
}
Example #3
0
int main(int argc, char* argv[])
{
    int rank, nproc;
    int ini, fim, rc;

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   /* verifica se execução será paralela*/ 
    if (nproc<2)
    {
        printf("\n\nParando programa necessiario no minimo 2 processos \n");
        MPI_Abort(MPI_COMM_WORLD, rc);
        exit(0);
    }

/* verifica se divisão do tamanho total matris por num processos deixa resto, caso deixe não faz pois o progema não está preparado para isso*/
    if (size % nproc > 0) {
        printf("\n\n Parando programa necessario ser um num divisivel por %d \n", size*size);
        MPI_Abort(MPI_COMM_WORLD, rc);
        exit(0);
     }


    if (rank == 0) {
        preenche(); 
    }

   /* Envia as matrizes em broadcast para todos os processos*/    
    MPI_Bcast(a, size*size, MPI_FLOAT, 0,MPI_COMM_WORLD);
    MPI_Bcast(b, size*size, MPI_FLOAT, 0,MPI_COMM_WORLD);
    MPI_Bcast(c, size*size, MPI_FLOAT, 0,MPI_COMM_WORLD);

   /*setar inicio e fim do for para cada processo*/ 
    ini = (size / nproc) * rank;
    fim = (size / nproc) * (rank + 1) - 1;

    
    mult(ini, fim);

   /*Obtem as mensagens de todos os processos*/ 
    MPI_Gather(c + (size/nproc*rank),
               size*size/nproc,
               MPI_FLOAT,
               c + (size/nproc*rank),
               size*size/nproc,
               MPI_FLOAT,
               0,
               MPI_COMM_WORLD);

/*    if (rank == 0) {
    	for (int i = 0; i < size; ++i) {
        for (int j = 0; j < size; ++j) {
	printf("%d\n", c[i][j]);
	}}   
    }*/

    MPI_Finalize();
    return 0;
}
Example #4
0
int main(){
         produtos *produto;
		int quant;
		
		
		do{
			printf("\nInformar o numero de produtos a ser cadastrado :");
			printf("\nFavor informar numero positivo maior que 0:");
			scanf("%d",&quant);
		}while(quant<=0);
		
		produto =alocarPrd(produto,quant);
		preenche(produto,quant);
		ValidarEstoque(produto,quant);
		listarProdutos(produto,quant);
		




	

		


	

system("pause");
return 0;

}
Example #5
0
int main(){
  int vetor[5];
  int tamanho=5;
  preenche(vetor, tamanho);
  imprimeVetor(vetor,tamanho);
  ordenaVetor(vetor,tamanho);
  imprimeVetor(vetor,tamanho);
  return 0;
}
Example #6
0
int main(){
	int vetor[TAM],tamanho=TAM;
	preenche(tamanho,vetor);
	printf("Vetor sem ordenar:\n");
	imprime(0, tamanho-1,vetor);
	mergeSort(vetor,0,tamanho-1);
	printf("Vetor ordenado:\n");
	imprime(0, tamanho-1,vetor);
	return 0;
}
Example #7
0
int main()
{
int A[10],B[10];
	
	printf("informe o 1 vetor: \n");
	preenche(A);
	printf("\ninforme o 2 vetor: \n");
	preenchevetor(B);
	calcula(A,B);
	system("pause");
	return 0;

}
void main(void)
{
    int opcao;
    do {
        clrscr();
        printf("MENU\n");
        printf("------\n");
        printf("(1) Preenche\n");
        printf("(2) Set-In\n");
        printf("(3) Set-Out\n");
        printf("(4) Lista\n");
        printf("(5) Sair\n");
        printf("\nOpcao: ");
        scanf("%d",&opcao);
        switch (opcao) {
        case 1: {
            preenche();
            break;
        }
        case 2: {
            int id;
            do {
                clrscr();
                printf("Set-In\nIdentificacao (0 a 9): ");
                scanf("%d",&id);
            } while (!(id>=0 && id<=9));
            set(id);
            break;
        }
        case 3: {
            int id;
            do {
                clrscr();
                printf("Set-Out\nIdentificacao (0 a 9): ");
                scanf("%d",&id);
            } while (!(id>=0 && id<=9));
            out(id);
            break;
        }
        case 4: {
            list();
            break;
        }
        }
    } while (opcao!=5);
    getch();
}
Example #9
0
/*
\brief função principal
*/
int main()
{
	int *vetor,v,  tamanho;
	float DP, med;
	
	printf("\n\t\tPROGRAMA PARA COLOCAR NUMEROS EM ORDEM CRESCENTE\n");
      	printf("\n");
	printf("\nDIGITE A QUANTIDADE DE NUMEROS:\n");
        tamanho = ler();
	vetor = preenche(tamanho);      	
	printf("%d\n\n",vetor[2]);
	if(vetor)
	{

		exibe(vetor,tamanho);
	}
       	else
		printf("\nNAO EH POSSIVEL GERAR NUMEROS");

	ordena(vetor, tamanho);
	med = media(vetor,tamanho);
	desviop(vetor,med,tamanho);
}
main(){

       
char caminho, tabuleiro[10][9];  
//Coordenadas inicial da seta (0,2)
int x=0,y=2,i,j;

//Preenche o labirinto
preenche(tabuleiro);

//inicializa a pilha
inicializa(&pilha);


printf("<- JOGO DA SETINHA -> \n");
printf("Desenvolvido por: Luis Gustavo Araujon\n");
printf("Obs.: Pressione qualquer tecla para cada interacao");


//Enquanto alguma coisa
while(tabuleiro[5][8]!=26){

         getchar();
         system("cls");
         imprime(tabuleiro); 
         printf("Cornedadas x,y: %d %d",x,y);
         if(tabuleiro[y][x+1]==-37){
          
              tabuleiro[y][x]=000;
              tabuleiro[y][++x]=26;
              push(&pilha,'d');
              //empilha a letra d (direita)                             
         
         }else if(tabuleiro[y+1][x]==-37){
             
               tabuleiro[y][x]=000;
               tabuleiro[++y][x]=25;
               push(&pilha,'b');
               //empilha a letra b (baixo)
                                       
         }else if (tabuleiro[y][x-1]==-37){
         
             tabuleiro[y][x]=000;
             tabuleiro[y][--x]=27;
             push(&pilha,'e');
             //empilha a letra e  (esquerda) 
         
         }else if(tabuleiro[y-1][x]==-37){
             
             tabuleiro[y][x]=000;
             tabuleiro[--y][x]=24;
             push(&pilha,'c');
             //empilha a letra c (cima)
         
         }else{              
              caminho=pop(&pilha);
              
              if(caminho=='d'){   
                                 
                  tabuleiro[y][x]=000;
                  tabuleiro[y][--x]=27;
                              
              }else if (caminho=='b'){
                
                 tabuleiro[y][x]=000;
                 tabuleiro[--y][x]=24;  
              
              }else if (caminho=='e'){
                    
                    tabuleiro[y][x]=000;
                    tabuleiro[y][++x]=26;
              
              }else if(caminho=='c'){
                    
                    tabuleiro[y][x]=000;
                    tabuleiro[++y][x]=25;
                    
              }      
         
         
         
         
         } 
   
   } 
 
 system("cls");
imprime(tabuleiro); 
printf("\\o/  Voce Saiu do Labirinto!!! \\o/ \n");


system("pause");
}
Example #11
0
int main()
{
  int i, j, k;
  int n, m;
  int numq, tamm;
  char dir;
  int lx, ly;
  
  fin = fopen("castle.in", "r");
  fout = fopen("castle.out", "w");
  /*  fin = stdin;*/
  /*fout = stdout;*/


  fscanf(fin, " %d %d", &m, &n);
  for(i=0; i<n; i++)
    for(j=0; j<m; j++){
      fscanf(fin, " %d", &castelo[i][j]);
      comp[i][j] = 0;
    }

  numq = 0;
  tamm = 0;
  for(i=0; i<n; i++)
    for(j=0; j<m; j++)
      if(comp[i][j] == 0){
	numq++;
	k = preenche(i, j, numq);
	tamc[numq-1] = k;
	if(k > tamm)
	  tamm = k;
	/*
	fprintf(stderr, "-->%d %d\n", numq, k);
	*/
      }
  /*
  for(i=0; i<n; i++){
    for(j=0; j<m; j++)
      fprintf(stderr, "%d ", comp[i][j]);
    fprintf(stderr, "\n");
  }
  */
  fprintf(fout, "%d\n%d\n", numq, tamm);

  tamm = 0;
  lx = ly = 0;
  dir = 'A';
  for(j=0; j < m; j++)
    for(i=n-1; i >= 0; i--){
      if(i > 0 &&
	 comp[i][j] != comp[i-1][j] &&
	 tamc[comp[i][j]-1] + tamc[comp[i-1][j]-1] > tamm)
	{
	  tamm = tamc[comp[i][j]-1] + tamc[comp[i-1][j]-1];
	  dir = 'N';
	  lx = i;
	  ly = j;
	}

     if(j < m-1 &&
	 comp[i][j] != comp[i][j+1] &&
	 tamc[comp[i][j]-1] + tamc[comp[i][j+1]-1] > tamm)
	{
	  tamm = tamc[comp[i][j]-1] + tamc[comp[i][j+1]-1];
	  dir = 'E';
	  lx = i;
	  ly = j;
	}
    }

  fprintf(fout, "%d\n%d %d %c\n", tamm, lx+1, ly+1, dir);

  return 0;
}