Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created November 12, 2024 16:05
Show Gist options
  • Select an option

  • Save vlaleli/7fc0f2293e37800fcc5d58c6f38caff9 to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/7fc0f2293e37800fcc5d58c6f38caff9 to your computer and use it in GitHub Desktop.
1
#include <iostream>
using namespace std;
int main() {
const int SIZE = 10;
int array1[SIZE];
int array2[SIZE];
int resultArray[SIZE];
for (int i = 0; i < SIZE; i++) {
array1[i] = rand() % 50 + 1;
array2[i] = rand() % 50 + 1;
}
for (int i = 0; i < SIZE; i++) {
resultArray[i] = array1[i] + array2[i];
}
cout << "First array: ";
for (int i = 0; i < SIZE; i++) {
cout << array1[i] << " ";
}
cout << endl;
cout << "Second array: ";
for (int i = 0; i < SIZE; i++) {
cout << array2[i] << " ";
}
cout << endl;
cout << "Addition result: ";
for (int i = 0; i < SIZE; i++) {
cout << resultArray[i] << " ";
}
cout << endl;
}
2
#include <iostream>
using namespace std;
int main()
{
const int N = 10;
int arr[N];
for (int i = 0; i < N; i++)
{
arr[i] = rand() % 201 - 100;
}
for (int i = 0; i < N; ++i)
{
cout << arr[i] << " ";
}
for (int i = N - 1; i >= 0; i--)
{
cout << arr[i] << " ";
}
const int HALF_SIZE = N / 2;
int firstHalf[HALF_SIZE];
int secondHalf[HALF_SIZE];
for (int i = 0; i < HALF_SIZE; i++)
{
firstHalf[i] = arr[i];
secondHalf[i] = arr[i + HALF_SIZE];
}
for (int i = 0; i < HALF_SIZE; i++)
{
cout << firstHalf[i] << " ";
}
cout << endl;
for (int i = 0; i < HALF_SIZE; i++)
{
cout << secondHalf[i] << " ";
}
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment