Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- void summArray() {
- const int size = 5;
- const int min_val = -50;
- const int max_val = 50;
- int arr1[size];
- int arr2[size];
- int arr3[size];
- srand(time(NULL));
- for (int k = 0; k < size; ++k) {
- arr1[k] = rand() % (max_val - min_val + 1)
- + min_val;
- arr2[k] = rand() % (max_val - min_val + 1)
- + min_val;
- }
- for (int k = 0; k < size; ++k) {
- arr3[k] = arr1[k] + arr2[k];
- }
- cout << "arr1: ";
- for (int k = 0; k < size; ++k) {
- cout << arr1[k] << " ";
- }
- cout << endl;
- cout << "arr2: ";
- for (int k = 0; k < size; cout << arr2[k++] << " ");
- cout << endl;
- cout << "arr3: ";
- for (int k = 0; k < size; ++k) {
- cout << arr3[k] << " ";
- }
- cout << endl;
- }
- void shiftArray(int shift) {
- const int size = 5;
- while (shift < 0)
- shift += size;
- while (shift > size)
- shift -= size;
- int arr1[size]{1, 2,3,4,5};
- int arr2[size];
- for (int k = 0; k < size; k++) {
- arr2[k] = arr1[(k + shift) % size];
- /*
- if (k + shift < size)
- arr2[k] = arr1[k + shift];
- else
- arr2[k] = arr1[k + shift - size];
- */
- }
- for (int k = 0; k < size; ++k) {
- cout << arr1[k] << "\t" << arr2[k] << endl;
- }
- }
- void slideSum() {
- const int size = 5;
- int arr1[size]{ 1, 2,3,4,5 };
- int arr2[size];
- arr2[0] = arr1[0];
- for (int k = 1; k < size; ++k)
- arr2[k] = arr2[k - 1] + arr1[k];
- for (int k = 0; k < size; ++k) {
- cout << arr1[k] << "\t" << arr2[k] << endl;
- }
- }
- void getNegativePositive() {
- const int size = 15;
- const int min_val = -25;
- const int max_val = 25;
- int arr1[size];
- for (int k = 0; k < size; ++k) {
- arr1[k] = rand() % (max_val - min_val + 1)
- + min_val;
- }
- cout << "arr1: ";
- for (int k = 0; k < size; ++k) {
- cout << arr1[k] << " ";
- }
- cout << endl;
- int positive = 0, negative = 0;
- for (int k = 0; k < size; ++k) {
- if(arr1[k] > 0)
- positive++;
- else if (arr1[k] < 0)
- negative++;
- }
- cout << "pos: " << positive << ", neg: " << negative << endl;
- cout << "zero: " << size - (positive + negative) << endl;
- }
- void multyTab() {
- const int size1 = 9;
- const int size2 = 5;
- int tab[size1][size2];
- for (int k = 0; k < size1; k++) {
- for (int n = 0; n < size2; n++) {
- tab[k][n] = (k + 1) * (n + 1);
- }
- }
- for (int n = 0; n < size2; n++) {
- for (int k = 0; k < size1; k++) {
- cout << tab[k][n] << "\t";
- }
- cout << endl;
- }
- }
- void sumDiag() {
- const int size = 5;
- const int min_val = -100;
- const int max_val = 100;
- srand(time(NULL));
- double arr[size][size];
- for (int k = 0; k < size; k++)
- for (int n = 0; n < size; n++)
- arr[k][n] = (rand() % (max_val - min_val + 1) + min_val) / 100.0;
- for (int k = 0; k < size; k++) {
- for (int n = 0; n < size; n++)
- cout << arr[k][n] << "\t";
- cout << "\n";
- }
- double sum{0}; // double sum = 0
- for (int k = 0; k < size; k++) {
- for (int n = 0; n < size; n++) {
- if (n == k)
- sum += arr[n][k];
- }
- }
- double sum1{ 0 };
- for (int k = 0; k < size; k++) {
- sum1 += arr[k][k];
- }
- cout << "sum: " << sum << endl;
- cout << "sum1: " << sum1 << endl;
- }
- void sqrTab() {
- const int size = 5;
- const int min_val = -10;
- const int max_val = 10;
- srand(time(NULL));
- double arr[size][size];
- for (int k = 0; k < size; k++) {
- for (int n = 0; n < size; n++) {
- arr[k][n] = (rand() % (max_val - min_val + 1) + min_val);
- cout << arr[k][n] << "\t";
- }
- cout << "\n";
- }
- double arr2[size][size];
- for (int k = 0; k < size; k++)
- for (int n = 0; n < size; n++)
- arr2[k][n] = arr[k][n] * arr[k][n];
- cout << endl;
- for (int k = 0; k < size; k++) {
- for (int n = 0; n < size; n++)
- cout << arr2[k][n] << "\t";
- cout << "\n";
- }
- }
- void main() {
- //shiftArray(-101);
- //slideSum();
- //getNegativePositive();
- //multyTab();
- //sumDiag();
- sqrTab();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement