Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- #define _USE_MATH_DEFINES
- #define a 2
- #define b 20
- float fill(); // функция для ввода элементов
- float sum(); // функция для подсчета суммы
- float print(); // функция для вывода суммы массива
- void fill(int* arr, int n, char c) { // функция для ввода элементов
- cout << "Creating " << n << " elements of " << " array " << c << ": " << endl; // Вводим значения массива A
- for (int i = 0; i < n; i++)
- {
- arr[i] = rand() % (b - a + 1) + a;
- cout << arr[i] << " ";
- }
- cout << endl;
- return;
- }
- int sum(int* arr, int n) { // функция для подсчета суммы
- int s = 0;
- for (int i = 0; i < n; i++)
- {
- s += arr[i];
- }
- return s;
- }
- void print(int sum, char c) { // функция для вывода суммы массива
- cout << "Sum of " << c << " array elements is " << sum << endl;
- return;
- }
- void analyse(int sa, int sb, char ca, char cb) {
- cout << endl << "Result:" << endl;
- if (sa > sb) {
- cout << "The array " << cb << " has the minimum sum" << endl;
- } else if (sa < sb) {
- cout << "The array " << ca << " has the minimum sum" << endl;
- } else {
- cout << "Arrays " << ca << " and " << cb << " have the same sum" << endl;
- }
- return;
- }
- int main(){
- srand(time(NULL));
- int n, m;
- int sa = 0, sb = 0; // sa = сумма чисел массива А, sb = сумма чисел массива В
- int* A;
- int* B;
- cout << "Enter n & m: ";
- cin >> n >> m;
- A = new int[n];
- B = new int[m];
- fill(A, n, 'A');
- fill(B, m, 'B');
- sa = sum(A, n);
- sb = sum(B, m);
- print(sa, 'A');
- print(sb, 'B');
- analyse(sa, sb, 'A', 'B');
- system("pause");
- delete[] A;
- delete[] B;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement