Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
/*2. Escreva um programa que receba do usuário as dimensões NUM_LIN e NUM_COL (não maiores que 20) e os dados de uma matriz bidimensional, converta-a em um vetor e imprima na tela os valores armazenados neste vetor. LINGUAGEM E TÉCNICA DE PROGRAMAÇÃO I - TT 214 EXERCÍCIO 2 AULA 7 WELLINGTON RENAN GONÇALVES RA 148232*/ #include <stdio.h> #define NUM_LIN 20 #define NUM_COL 20 int main(){ int matriz[NUM_LIN][NUM_COL]; int vetor[NUM_LIN*NUM_COL]; int l, c; int nlin, ncol; int aux, k; printf("Entre com o numumeros de linhas e colunas: \n"); scanf("%d %d", &nlin, &ncol); printf("\nEntre com os elementos da matriz: \n"); for (l=0; l < nlin; l++){ for (c=0; c < ncol; c++){ scanf("%d",&matriz[l][c]);}} printf("\nA matriz eh:\n"); for (l=0; l < nlin; l++){ for (c=0; c < ncol; c++){ printf("%d\t",matriz[l][c]);} printf("\n");} /*LINEARIZAÇÃO DA MATRIZ*/ for (l=0; l < nlin; l++){ for (c=0; c < ncol; c++){ k = l*ncol + c; aux = matriz[l][c]; vetor[k] = aux;}} printf("\n O vetor eh:\n"); for (k=0; k < nlin*ncol; k++){ printf("%d", vetor[k]);} return 0; }
Compartilhar