nikolas_serafini

Lista 5 - Exercício 17

Jul 6th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main()
  5. {
  6.   int i,j,begin,end,par = 0, impar = 0,matrix[8][20];
  7.  
  8.   srand(time(NULL));
  9.  
  10.   input:
  11.   printf("Insira o intervalo desejado :\n");
  12.   scanf("%d %d",&begin,&end);
  13.   if (begin > end)
  14.     goto input;
  15.  
  16.   for (i = 0; i < 8; i++)
  17.   {
  18.       for (j = 0; j < 20; j++)
  19.       {
  20.         matrix[i][j] = rand() % (end-begin+1) + begin;
  21.         printf("%d ",matrix[i][j]);
  22.         if (matrix[i][j] % 2 == 0)
  23.           par++;
  24.         else
  25.           impar++;
  26.       }
  27.       printf("\n");
  28.   }
  29.  
  30.   printf("\nQuantidade de numeros pares : %d\nPorcentagem de pares : %.3f\nQuantidade de numeros impares : %d\nPorcentagem de impares : %.3f\n",par,(float)par/160*100,impar,(float)impar/160*100);
  31.  
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment