Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // cout, endl
- #include <iomanip> // setw
- #include <cstdlib> // rand, srand, RAND_MAX
- #include <ctime> // time, NULL
- #define D 30
- using namespace std;
- void init(float arr[], unsigned n) {
- srand(time(NULL));
- for(int i = 0; i < n; i++) {
- arr[i] = rand()/float(RAND_MAX) * 15 - 5;
- cout << setw(2) << i+1 << ". " << arr[i] << endl;
- }
- }
- float atlag(float arr[], unsigned n) {
- float sum = 0.0;
- int cnt = 0;
- for(int i = 0; i < n; i++) {
- sum += arr[i];
- cnt++;
- }
- return sum/cnt;
- }
- bool fagyos_e(float arr[], unsigned n) {
- for(int i = 0; i < n; i++) {
- if(arr[i] <= 0.0) {
- return true;
- }
- }
- return false;
- }
- float legmelegebb(float arr[], unsigned n) {
- float max = -5.0;
- for(int i = 0; i < n; i++) {
- if(arr[i] > max) {
- max = arr[i];
- }
- }
- return max;
- }
- bool futes(float arr[], unsigned n) {
- // és mégis milyen hűvösre kellene bekapcsolni a fűtést? csinálok egy küszöböt, hogy be lehessen állítani...
- float kuszob = 5.0;
- for(int i = 0; i < 15; i++) {
- if(arr[i] < kuszob) {
- return true;
- }
- }
- return false;
- }
- int main() {
- float data[D] = {};
- init(data, D);
- cout << endl << "Átlag: " << atlag(data, D);
- cout << endl << "Fagyos-e? " << (fagyos_e(data, D) ? "Igen" : "Nem");
- cout << endl << "Csúcshő: " << legmelegebb(data, D);
- cout << endl << "15-e előtt fűtés kell-e? " << (futes(data, D) ? "Igen" : "Nem");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment