Jump to content

Random máximo e mínimo


BolsoRoto
 Share

Recommended Posts

#include<stdio.h>
#include <stdlib.h>
int soma=0,a[10][10],j,i,max,min,max2,min2;
float media1=0, media2=0, media3=0, b[10]={0,0,0,0,0,0,0,0,0,0},c[10]={0,0,0,0,0,0,0,0,0,0};
main(){
max=0;
min=11;
max2=0;
min2=11;
srand(time(NULL));
for(i=0;i<10;i++){
 for(j=0;j<10;j++){
a[i][j]=rand()%10+1;
media1 = media1 + a[i][j];
printf("a[%d][%d] = %d \n \n", i,j, a[i][j] );
b[i]+=a[i][j];
c[j]+=a[i][j];
 }
}
for(i=0;i<10;i++){
 b[i]/=10;
 printf("Media da linha %d : %.2f \n \n ",i,b[i]);
}
 for(j=0;j<10;j++){
 c[j]/=10;
 printf("Media da coluna %d : %.2f \n \n",j,c[j]);
}
media1 = media1/ 100;
printf("Media de todos os numeros da tabela: %.2f \n \n",media1);
system("pause");
}

Este é o codigo que para ja temos e so nos falta o minimo e o maximo de cada linha. ajuda sff.

Edited by thoga31
Tags code + GeSHi + remoção tags quote
Link to comment
Share on other sites

achas que assim chegas lá ?

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

#define WIDTH  10
#define HEIGHT 10

int main(void) {
   int i, j, matrix[HEIGHT][WIDTH];
   double result;

   if (WIDTH <= 0 && HEIGHT <= 0) {
       printf("ups ... tamanhos invalidos ... \n");
       return -1;
   }

   srand(time(NULL));

   // preencher a matrix com valores aleatórios de 1 a 10
   for (i = 0; i < HEIGHT; ++i)
       for (j = 0; j < WIDTH; ++j)
           matrix[i][j] = (rand() % 10) + 1;

   // calcular a media da linha
   for (i = 0; i < HEIGHT; ++i) {
       result = 0.0;
       for (j = 0; j < WIDTH; ++j) {
           // TODO
       }
       printf("a media da linha %d e : %lf\n", j, result / WIDTH);
   }

   // calcular o valor minino da linha
   for (i = 0; i < HEIGHT; ++i) {
       result = matrix[i][0];
       for (j = 1; j < WIDTH; ++j) {
           // TODO
       }
       printf("o valor minimo da linha %d e : %lf\n", j, result);
   }

   // calcular o valor maximo da linha
   for (i = 0; i < HEIGHT; ++i) {
       result = matrix[i][0];
       for (j = 1; j < WIDTH; ++j) {
           // TODO
       }
       printf("o valor minimo da linha %d e : %lf\n", j, result);
   }

   // calcular a media da linha
   for (j = 0; j < WIDTH; ++j) {
       result = 0.0;
       for (i = 0; i < HEIGHT; ++i) {
           // TODO
       }
       printf("a media da coluna %d e : %lf\n", i, result / HEIGHT);
   }

   // calcular o valor minino da coluna
   for (j = 1; j < WIDTH; ++j) {
       result = matrix[0][j];
       for (i = 0; i < HEIGHT; ++i) {
           // TODO
       }
       printf("o valor minimo da coluna %d e : %lf\n", i, result);
   }

   // calcular o valor maximo da coluna
   for (j = 1; j < WIDTH; ++j) {
       result = matrix[0][j];
       for (i = 0; i < HEIGHT; ++i) {
           // TODO
       }
       printf("o valor minimo da coluna %d e : %lf\n", i, result);
   }

   // calcular a media total de todos os valores da metrix
   result = matrix[i][0];
   for (j = 1; j < WIDTH; ++j) {
       for (i = 0; i < HEIGHT; ++i) {
           // TODO
       }
   }
   printf("a media total de todos os valores e: %lf\n", result / (WIDTH * HEIGHT));

   return 0;
}
Edited by HappyHippyHippo
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.