Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
PROVA DE 2015 ALGORITMOS 1) 2) int checaMovimentacao(int lin,int col,int nLin,int nCol,int tabuleiro[8][8]) { if(lin<8 && lin>=0) { if(col<8 && col>=0) { if(nLin<8 && nLin>=0) { if(nCol<8 && nCol>=0) { if(tabuleiro[lin][col]==1) { if(nCol==col) { if(nLin > lin) { if(nLin-lin < 3) { if(tabuleiro[nLin][nCol]==0) { return 0; } else { return 1; } } } } } } } } } return -1; } int main() { int tabu[8][8] = {0}; int i; for(i=0; i<8; i++) { tabu[0][i]=2; tabu[1][i]=1; tabu[6][i]=2; tabu[7][i]=2; } int val =checaMovimentacao(1,0,1,0,tabu); if(val==0) { printf("Movimentacao possivel"); } else if(val == 1) { printf("Movimentacao possivel, posicao ocupada"); } else { printf("Movimentacao invalida"); } return 0; } 3) typedef struct st_produto { int codigo; char nome[100]; int vendas[2]; }Produto; int funcao (Produto p[], int tam) { int i, vendastotalmaior = -1, vendastotal2 = 0, indice, j; for (i=0;i<tam;i++) { vendastotal2 = 0; for(j=0; j<12; j++) { vendastotal2 = vendastotal2 + p[i].vendas[j]; } if (vendastotalmaior < vendastotal2) { vendastotalmaior = vendastotal2; indice = i; } } return indice; } int main () { printf("LEITURA DE DADOS DA ESTRUTURA\n CODIGO/NOME/VENDAS\n"); Produto p[100]; int i, tam, j; printf("Digite quantos produtos serao analisados: "); scanf("%d", &tam); for (i=0;i<tam;i++) { printf("Codigo: "); scanf("%d", &p[i].codigo); printf("Nome: "); fflush(stdin); gets(p[i].nome); printf("Vendas: \n"); for (j=0; j<3; j++) { scanf("%d", &p[i].vendas); } printf("\n"); } printf("O nome e o codigo do produto de maior venda foram: \n"); puts(p[funcao(p, tam)].nome); printf("%d", p[funcao(p, tam)].codigo); return 0; }
Compartilhar