Advertisement
morikawa

campo_minhocas

Oct 29th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. #define TAM 100
  6.  
  7. void gerarProdutividade(int campo[TAM][TAM], int N, int M){
  8.   int i,j;
  9.   for(i=0;i<N;i++)
  10.     for(j=0;j<M;j++)
  11.       campo[i][j]=rand()%501;
  12. }
  13.  
  14. void verificarProduccao (int campo[TAM][TAM], int N, int M, int *maiorProd){
  15.   int i, j, soma;
  16.   for(i=0;i<N;i++){
  17.     soma=0;
  18.     for(j=0;j<M;j++){
  19.       soma=soma+campo[i][j];
  20.     }
  21.     if(soma>*maiorProd){
  22.       *maiorProd = soma;
  23.     }
  24.   }
  25.   for(j=0;j<M;j++){
  26.     soma=0;
  27.     for(i=0;i<N;i++){
  28.       soma=soma+campo[i][j];
  29.     }
  30.     if(soma>*maiorProd){
  31.       *maiorProd = soma;
  32.     }
  33.   }
  34. }
  35.  
  36. int main(void) {
  37.   int campo[TAM][TAM], N, M, maiorProd=0;
  38.   printf("Insira os tamanhos do retangulo: ");
  39.   scanf("%d %d", &N, &M);
  40.   srand(time(NULL));
  41.   gerarProdutividade(campo, N, M);
  42.   verificarProduccao(campo, N, M, &maiorProd);
  43.   printf("%d", maiorProd);
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement