Last active
May 8, 2022 20:56
-
-
Save divanibarbosa/9777de0f05551c09c859b5c0e5fccfa5 to your computer and use it in GitHub Desktop.
Atividade Matrizes e Vetores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Criado por: profa. Divani Barbosa Gavinier | |
// Curriculo Lattes: http://lattes.cnpq.br/8503400830635447 | |
// divanibarbosa@gmail.com | |
/* | |
Desenvolver um programa em C para os seguinte problema: | |
Ler do usuário os elementos de uma matriz A de valores inteiros distintos de dimensão nxn (n<=10). | |
Gerar dois vetores V e W, formados respectivamente pela linha de A correspondente ao maior elemento e pela coluna de A correspondente ao menor elemento . | |
Escrever a matriz A e os vetores V e W. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
main() { | |
int i, j, n; | |
while (1) { | |
printf("Informe a dimensao da matriz quadrada: "); | |
scanf("%d",&n); | |
if (n>10 || n<=0) printf("ATENCAO informe um valor menor que 11 e maior que 0\n"); | |
else break; | |
} | |
int A[n][n], V[n], W[n]; | |
int maior, menor, jmenor, imaior; | |
printf("Forneça %d valores para matriz A:\n",n*n); | |
for(i=0; i<n; i++) { | |
for(j=0; j<n;j++) { | |
printf("A[%d][%d] = ",i,j); | |
scanf("%d",&A[i][j]); | |
} | |
} | |
printf("\nConteudo matriz A:\n"); | |
for(i=0; i<n; i++) { | |
for(j=0; j<n;j++) { | |
printf("%d\t",A[i][j]); | |
} | |
printf("\n"); | |
} | |
/* Encontrando o maior e menor valor e sua posição na matriz */ | |
maior=menor=A[0][0]; | |
jmenor=imaior=0; | |
for(i=0; i<n; i++) { | |
for(j=0; j<n; j++) { | |
if(A[i][j] > maior) { | |
maior = A[i][j]; | |
imaior = i; | |
} | |
if(A[i][j] < menor) { | |
menor = A[i][j]; | |
jmenor = j; | |
} | |
} | |
} | |
/* Atribuindo valores aos vetores V e W */ | |
for(i=0; i<n; i++) { | |
V[i] = A[imaior][i]; | |
W[i] = A[i][jmenor]; | |
} | |
printf("\nConteudo vetor V formado pela linha de A correspondente ao maior elemento = %d\n",maior); | |
for(i=0; i<n; i++) printf("%d\t",V[i]); | |
printf("\n\n"); | |
printf("Conteudo vetor W formado pela coluna de A correspondente ao menor elemento = %d\n",menor); | |
for(i=0; i<n; i++) printf("%d\t",W[i]); | |
printf("\n\n"); | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment