Guest User

Untitled

a guest
Jan 16th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. //Wylosować n liczb z przedziału [-20,15] i obliczyć średnią, ale tylko z liczb nieparzystych
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <conio.h>
  6. #include <cstdlib>
  7. #include <time.h>
  8.  
  9. using namespace std;
  10.  
  11. int n, licznik=0, sum=0;
  12.  
  13. int main()
  14. {
  15. srand(time(NULL));
  16. cout << "Ile liczb chcesz wylosowac? ";
  17. cin >> n;
  18.  
  19. int *tab;
  20. tab = new int[n];
  21.  
  22. for (int i = 0; i < n; i++)
  23. {
  24. tab[i] = rand()%36-20;
  25. cout << tab[i]<<endl;
  26. if (tab[i] % 2 != 0)
  27. {
  28. sum += tab[i];
  29. licznik++;
  30. }
  31. }
  32. cout << "Srednia wynosi: " << sum / licznik;
  33. delete [] tab;
  34. _getch();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment