Возможно, не самое эффективное решение #include <iostream> #include <cstdlib> #include <ctime> int main() { using namespace std; const int N = 10; int A[N]; srand(time(0)); for (int i = 0; i < N; ++i) A[i] = rand() % 201 - 100;
//Вывод исходного массива на экран for (int i = 0; i < N; ++i) cout << A[i] << " "; cout << endl;
//Подсчитаем количества положительных и отрицательных int kpos = 0, kneg = 0; for (int i = 0; i < N; i++) if (A[i] > 0) ++kpos; else ++kneg;
int * Apos = new int[kpos]; int * Aneg = new int[kneg]; int pos = 0, neg = 0; for (int i = 0; i < N; ++i) if (A[i] > 0) Apos[pos++] = A[i]; else Aneg[neg++] = A[i];
for (int i = 0; i < N; ++i) if (i < kpos) A[i] = Apos[i]; else A[i] = Aneg[i - kpos];
delete[] Apos; delete[] Aneg;
//Вывод полученного массива на экран for (int i = 0; i < N; ++i) cout << A[i] << " "; cout << endl; return 0; }
Sub Ìàêðîñ1() Dim Sum(heigth - 1, width - 1) Dim Product(heigth - 1, width - 1)
For i = 0 To heigth - 1 For j = 0 To width - 1 Sum(i, j) = i + j Product(i, j) = i * j Next j Next i
Call Show(Sum, 0, 0) Call Show(Product, 0, 12) End Sub
Sub Show(ByRef m, dx, dy) For i = 0 To heigth - 1 For j = 0 To width - 1 ActiveSheet.Cells(dx + i + 1, dy + j + 1).Value = Hex(m(i, j)) Next j Next i End Sub
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
{
using namespace std;
const int N = 10;
int A[N];
srand(time(0));
for (int i = 0; i < N; ++i)
A[i] = rand() % 201 - 100;
//Вывод исходного массива на экран
for (int i = 0; i < N; ++i)
cout << A[i] << " ";
cout << endl;
//Подсчитаем количества положительных и отрицательных
int kpos = 0, kneg = 0;
for (int i = 0; i < N; i++)
if (A[i] > 0)
++kpos;
else
++kneg;
int * Apos = new int[kpos];
int * Aneg = new int[kneg];
int pos = 0, neg = 0;
for (int i = 0; i < N; ++i)
if (A[i] > 0)
Apos[pos++] = A[i];
else
Aneg[neg++] = A[i];
for (int i = 0; i < N; ++i)
if (i < kpos)
A[i] = Apos[i];
else
A[i] = Aneg[i - kpos];
delete[] Apos;
delete[] Aneg;
//Вывод полученного массива на экран
for (int i = 0; i < N; ++i)
cout << A[i] << " ";
cout << endl;
return 0;
}
Const width = 10
Sub Ìàêðîñ1()
Dim Sum(heigth - 1, width - 1)
Dim Product(heigth - 1, width - 1)
For i = 0 To heigth - 1
For j = 0 To width - 1
Sum(i, j) = i + j
Product(i, j) = i * j
Next j
Next i
Call Show(Sum, 0, 0)
Call Show(Product, 0, 12)
End Sub
Sub Show(ByRef m, dx, dy)
For i = 0 To heigth - 1
For j = 0 To width - 1
ActiveSheet.Cells(dx + i + 1, dy + j + 1).Value = Hex(m(i, j))
Next j
Next i
End Sub