Advertisement
xlrnxnlx

maysa

Oct 25th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include "vetores.h"
  2. #include <cmath>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. void ExibeVetor(VETOR &v, int n){
  10.     for (int i = 0; i < n; i++)
  11.         cout << v[i] << '\t';
  12.         cout << endl;  
  13. }
  14.  
  15. /* vai gerar um número randomico entre 'min' e 'max' */
  16. unsigned int randomico( unsigned int min, unsigned int max ){
  17.     double escala = ( double )rand()/RAND_MAX;
  18.     return ( max - min + 1 ) * escala + min;
  19. }
  20.  
  21. void sortear (VETOR &v, int n){ //sortear valores entre 30 e 100
  22.     for (int i = 0; i < n; i++)
  23.           v[i] =  randomico( 30, 100 );
  24. }
  25.      
  26. int mediaPares(VETOR &v, int n){ //media dos componentes pares
  27.     int s = 0; int media, pares = 0;
  28.     for(int i = 0; i < n;i++){
  29.         if(v[i]%2==0){
  30.             pares++;
  31.             s+=v[i];
  32.         }
  33.     }
  34.     media = s/pares;
  35.     return media;
  36. }
  37.  
  38. int quantImpares (VETOR &v, int n){ //contar os impares
  39.     int q=0;
  40.     for (int i = 0; i < n; i++)
  41.        if (v[i]% 2 != 0) q++;
  42.      return q;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement