Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wylosować n liczb z przedziału [-20,15] i obliczyć średnią, ale tylko z liczb nieparzystych
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int n, licznik=0, sum=0;
- int main()
- {
- srand(time(NULL));
- cout << "Ile liczb chcesz wylosowac? ";
- cin >> n;
- int *tab;
- tab = new int[n];
- for (int i = 0; i < n; i++)
- {
- tab[i] = rand()%36-20;
- cout << tab[i]<<endl;
- if (tab[i] % 2 != 0)
- {
- sum += tab[i];
- licznik++;
- }
- }
- cout << "Srednia wynosi: " << sum / licznik;
- delete [] tab;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment