Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- /* 17. Preencha, com números randômicos, uma matriz de 8 linhas por 20 colunas. A faixa dos
- números aleatórios deverá ser solicitada ao usuário. Calcule a quantidade de números pares e
- impares em cada linha da matriz. Calcule também o percentual destes em relação a quantidade
- total de números da matriz.
- Exiba a matriz num formato tabular indicando as quantidades e percentuais calculados. */
- int main()
- {
- srand(time(NULL));
- int i,j,quantLinhas,quantColunas,total=0,limiteInferior,limiteSuperior;
- printf("\n Digite a quantidade de linhas e colunas da matriz: ");
- scanf("%d %d",&quantLinhas,&quantColunas);
- printf("\n Digite o limite inferior e superior do sorteio: ");
- scanf("%d %d",&limiteInferior,&limiteSuperior);
- int matriz[quantLinhas][quantColunas];
- float estatistica[quantLinhas][4];
- for(i=0;i<quantLinhas;i++)
- {
- for(j=0;j<quantColunas;j++)
- {
- estatistica[i][j]=0;
- }
- printf("\n");
- }
- printf("\n Matriz:\n ");
- for(i=0;i<quantLinhas;i++)
- {
- for(j=0;j<quantColunas;j++)
- {
- matriz[i][j]=(rand()%(limiteSuperior-limiteInferior+1)+limiteInferior);
- printf("%2d ",matriz[i][j]);
- total++;
- if(matriz[i][j]%2==0)
- {
- estatistica[i][0]++;
- }else{
- estatistica[i][1]++;
- }
- }
- printf("\n");
- }
- printf("\n Estatistica:\n");
- printf("\n P I Pp Ip");
- printf("\n");
- for(i=0;i<quantLinhas;i++)
- {
- estatistica[i][2]=((estatistica[i][0]*100)/total);
- estatistica[i][3]=((estatistica[i][1]*100)/total);
- for(j=0;j<4;j++)
- {
- printf("%.2f ",estatistica[i][j]);
- }
- printf("\n");
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement