Guião laboratorial n.º 1 – exercício 14

“Desenvolva uma função que receba o endereço inicial e as dimensões (i.e., nº de linhas e nº de colunas) de uma matriz de números inteiros e a preencha com valores aleatórios entre 1 e 100.”


#include <stdio.h>
#include <stdlib.h>

#define linhas 10
#define colunas 10

void aleatorio(int l, int c,int *a){
int *p, i=0,j=0;
p=a;
//random
time_t t;
srand((unsigned) time(&t));

for(i=0; i<l ; i++){
    for(j=0; j<c ; j++,p++){
     *p=rand() % 100;
    }
}
p=a;
for(i=0 ; i<l ; i++){
    for(j=0; j<c ; j++, p++){
      printf("%d\t", *p);
    }
  printf("\n");
}
}
int main()
{
int vector[linhas][colunas]={};
aleatorio(linhas, colunas, vector);



return 0;
}

ajuda(random): link

Tags :

0 thoughts on “Guião laboratorial n.º 1 – exercício 14”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.