0% acharam este documento útil (0 voto)
20 visualizações13 páginas

Luana Maria Gusmão de Lima

Enviado por

Nicolau Luana
Direitos autorais
© © All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato PDF, TXT ou leia on-line no Scribd
0% acharam este documento útil (0 voto)
20 visualizações13 páginas

Luana Maria Gusmão de Lima

Enviado por

Nicolau Luana
Direitos autorais
© © All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato PDF, TXT ou leia on-line no Scribd
Você está na página 1/ 13

Luana Maria Gusmão de lima

QUESTÃO 1

int main() {

int vetor[5];

printf("Digite 5 valores inteiros:\n");

for (int i = 0; i < 5; i++) {

printf("Elemento %d: ", i + 1);

scanf("%d", &vetor[i]);

int soma = 0;

for (int i = 0; i < 5; i++) {

soma += vetor[i];

printf("A soma dos elementos do vetor e: %d\n", soma);

return 0;

------------------------------------------------------------------

QUESTÃO 2

int main() {
char nomes[7][50]; // Cada nome pode ter até 49 caracteres

printf("Digite 7 nomes:\n");

for (int i = 0; i < 7; i++) {

printf("Nome %d: ", i + 1);

scanf("%s", nomes[i]);

int maior_tamanho = strlen(nomes[0]);

char maior_nome[50];

strcpy(maior_nome, nomes[0]);

for (int i = 1; i < 7; i++) {

if (strlen(nomes[i]) > maior_tamanho) {

maior_tamanho = strlen(nomes[i]);

strcpy(maior_nome, nomes[i]);

printf("O nome com o maior numero de caracteres e: %s\n", maior_nome);

return 0;

----------------------------------------------------------------------------
QUESTÃO 3

int main() {

char nomes[7][50]; // Cada nome pode ter até 49 caracteres

printf("Digite 7 nomes:\n");

for (int i = 0; i < 7; i++) {

printf("Nome %d: ", i + 1);

scanf("%s", nomes[i]);

int menor_tamanho = strlen(nomes[0]);

char menor_nome[50];

strcpy(menor_nome, nomes[0]);

for (int i = 1; i < 7; i++) {

if (strlen(nomes[i]) < menor_tamanho) {

menor_tamanho = strlen(nomes[i]);

strcpy(menor_nome, nomes[i]);

printf("O nome com o menor numero de caracteres e: %s\n", menor_nome);


return 0;

-----------------------------------------------------------------------------------------------

QUESTÃO 4

int comparar(const void *a, const void *b) {

return (*(int*)a - *(int*)b);

int main() {

srand(time(NULL));

int vetor[10];

for (int i = 0; i < 10; i++) {

vetor[i] = rand() % 101;

printf("Vetor antes da ordenacao:\n");

for (int i = 0; i < 10; i++) {

printf("%d ", vetor[i]);

printf("\n");
qsort(vetor, 10, sizeof(int), comparar);

printf("\nVetor apos a ordenacao em ordem crescente:\n");

for (int i = 0; i < 10; i++) {

printf("%d ", vetor[i]);

printf("\n");

return 0;

---------------------------------------------------------------------------------------------

QUESTÃO 5

int main() {

int vetor[8];

printf("Digite os 8 elementos do vetor:\n");

for (int i = 0; i < 8; i++) {

printf("Elemento %d: ", i + 1);

scanf("%d", &vetor[i]);

printf("\nVetor na ordem inversa:\n");

for (int i = 7; i >= 0; i--) {

printf("%d ", vetor[i]);

}
printf("\n");

return 0;

------------------------------------------------------------------------------

QUESTÃO 6

void preencher_vetores(int vetor1[], int vetor2[], int n) {

printf("Digite os elementos do primeiro vetor:\n");

for (int i = 0; i < n; i++) {

printf("Elemento %d: ", i+1);

scanf("%d", &vetor1[i]);

printf("\nDigite os elementos do segundo vetor:\n");

for (int i = 0; i < n; i++) {

printf("Elemento %d: ", i+1);

scanf("%d", &vetor2[i]);

void somar_vetores(int vetor1[], int vetor2[], int vetor_soma[], int n) {

for (int i = 0; i < n; i++) {

vetor_soma[i] = vetor1[i] + vetor2[i];


}

void exibir_vetor(int vetor[], int n) {

printf("[");

for (int i = 0; i < n; i++) {

printf("%d", vetor[i]);

if (i < n - 1) {

printf(", ");

printf("]\n");

int main() {

int vetor1[5], vetor2[5], vetor_soma[5];

preencher_vetores(vetor1, vetor2, 5);

somar_vetores(vetor1, vetor2, vetor_soma, 5);

printf("Primeiro vetor: ");

exibir_vetor(vetor1, 5);

printf("Segundo vetor: ");


exibir_vetor(vetor2, 5);

printf("Vetor soma: ");

exibir_vetor(vetor_soma, 5);

return 0;

-------------------------------------------------------------------------------

QUESTÃO 7

void inicializar_e_exibir_matriz() {

int matriz[3][3] = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

printf("Matriz:\n");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

printf("%d ", matriz[i][j]);

printf("\n"); // Pular para a próxima linha após exibir uma linha completa

}
}

int main() {

// Chamar a função para inicializar e exibir a matriz

inicializar_e_exibir_matriz();

return 0;

---------------------------------------------------------------------------------

QUESTÃO 8

void somar_e_exibir_matrizes() {

int matriz1[3][3] = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

int matriz2[3][3] = {

{9, 8, 7},

{6, 5, 4},

{3, 2, 1}

};

int matriz_resultado[3][3] = {0};

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {

matriz_resultado[i][j] = matriz1[i][j] + matriz2[i][j];

printf("Matriz 1:\n");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

printf("%d ", matriz1[i][j]);

printf("\n");

printf("\nMatriz 2:\n");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

printf("%d ", matriz2[i][j]);

printf("\n");

printf("\nMatriz Resultado:\n");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

printf("%d ", matriz_resultado[i][j]);


}

printf("\n");

int main() {

// Chamar a função para somar e exibir as matrizes

somar_e_exibir_matrizes();

return 0;

------------------------------------

QUESTÃO 9

int matrizes_sao_identicas(int matriz1[3][3], int matriz2[3][3]) {

// Verificar se cada elemento das matrizes é igual

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

if (matriz1[i][j] != matriz2[i][j]) {

return 0; // Se encontrar um elemento diferente, as matrizes não são idênticas

return 1; // Se nenhum elemento diferente for encontrado, as matrizes são idênticas

int main() {
int matriz1[3][3] = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

int matriz2[3][3] = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

if (matrizes_sao_identicas(matriz1, matriz2)) {

printf("As matrizes são idênticas.\n");

} else {

printf("As matrizes não são idênticas.\n");

return 0;

------------------------------------------------------------------------------------

QUESTÃO 10

int encontrar_menor_elemento(int matriz[][3], int linhas, int colunas) {

int menor = matriz[0][0]; // Assume que o primeiro elemento é o menor

for (int i = 0; i < linhas; i++) {


for (int j = 0; j < colunas; j++) {

if (matriz[i][j] < menor) {

menor = matriz[i][j];

return menor;

int main() {

int matriz[3][3] = {

{9, 8, 7},

{6, 5, 4},

{3, 2, 1}

};

int linhas = sizeof(matriz) / sizeof(matriz[0]);

int colunas = sizeof(matriz[0]) / sizeof(matriz[0][0]);

int menor = encontrar_menor_elemento(matriz, linhas, colunas);

printf("O menor elemento da matriz é: %d\n", menor);

return 0;

Você também pode gostar