Phoenix_x

Untitled

Nov 29th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. void enterData(int numbers[], int &size);
  6. void multiplicationInRange(int numbers[], int size);
  7. void notZeroSumZeroCount(int numbers[], int size);
  8.  
  9. void main()
  10. {
  11.     int numbers[18];
  12.     int size = 0;
  13.  
  14.     while (true)
  15.     {
  16.         int option;
  17.         cout << "Izberi 1 za vavezdane na razmernost i chisla" << endl;
  18.         cout << "Izberi 2 za namirane na proizvedenie ot polozitelni chisla v daden interval" << endl;
  19.         cout << "Izberi 3 za suma ot nenulevi i broj nulevi." << endl;
  20.         cin >> option;
  21.  
  22.         switch (option)
  23.         {
  24.         case 1:
  25.             enterData(numbers, size);
  26.             break;
  27.         case 2:
  28.             multiplicationInRange(numbers, size);
  29.             break;
  30.         case 3:
  31.             notZeroSumZeroCount(numbers, size);
  32.             break;
  33.  
  34.         default:
  35.             cout << "Nevaliden vhod" << endl;
  36.         }
  37.     }
  38. }
  39.  
  40. void enterData(int numbers[], int &size)
  41. {
  42.     cout << "Broj chisla: ";
  43.     cin >> size;
  44.  
  45.     while (size < 0 || size > 18)
  46.     {
  47.         cout << "Nevaliden razmer!" << endl;
  48.         cout << "Vavedi razmer otnovo: ";
  49.         cin >> size;
  50.     }
  51.  
  52.  
  53.     for (int i = 0; i < size; i++)
  54.     {
  55.         cin >> numbers[i];
  56.     }
  57. }
  58.  
  59. void multiplicationInRange(int numbers[], int size)
  60. {
  61.     int min;
  62.     cout << "Min: ";
  63.     cin >> min;
  64.  
  65.     int max;
  66.     cout << "Max: ";
  67.     cin >> max;
  68.  
  69.     int multiply = 1;
  70.  
  71.     for (int i = 0; i < size; i++)
  72.     {
  73.         if (numbers[i] >= min && numbers[i] <= max && numbers[i] > 0)
  74.         {
  75.             multiply *= numbers[i];
  76.         }
  77.     }
  78.  
  79.     cout << "Proizvedenie: " << multiply << endl;
  80. }
  81.  
  82. void notZeroSumZeroCount(int numbers[], int size)
  83. {
  84.     int sum = 0;
  85.     int count = 0;
  86.  
  87.     for (int i = 0; i < size; i++)
  88.     {
  89.         if (numbers != 0)
  90.         {
  91.             sum += numbers[i];
  92.         }
  93.  
  94.         else
  95.         {
  96.             count++;
  97.         }
  98.     }
  99.  
  100.     cout << "Suma: " << sum << endl;
  101.     cout << "Broj: " << count << endl;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment