I'm new to this so go easy on me. I typed up some code and I checked to make sure all my loops were closed. Every time I go to build the solution, it says it's successful, but when I try to start without debugging, it'll bring up the command prompt and act the way it should. Then, right away, a pop up window says "ConsoleApplication1.exe has stopped working" and it won't let me input anything. Please help, I've spent hours trying to figure out what's wrong and have come up with nothing.
Here's the code:
#include <iostream>
using namespace std;
int main() {
int min = 10000;
int size = 10;
int* i = 0;
int* arrayA = new int { size };
int* arrayB = new int { size };
int* arrayC = new int { size };
for (int i = 0; i < size; i++) {
if (i * 2 < size) {
arrayB[i] = arrayA[i * 2];
arrayB[i * 2] = arrayA[i];
}
}
for (int i = 0; i < size; i++) {
arrayC[i] = arrayA[i] + arrayB[i];
}
for (int i = 0; i < (size + 1) / 2; i++) {
if (arrayC[i] < min) {
min = arrayC[i];
}
}
cout << "Min = " << min << endl;
return 0;
}
Okay, so I changed that and it worked. However, I need it to switch characters in arrays.
Write a program to swap an array element (array A) with the element at twice its index
position. If twice the index position does not exist, no swapping will happen. Store this in a
new array (array B) and store the sum of the original and new array in another array (array
C). Find the minimum of the left half of the final array C. Input array A size and elements.
Please submit output screenshots with both odd and even number array sizes.
For example,
Say, size = 10 and array A elements input are 4 5 8 12 34 56 1 0 22 7
Array A = 4 5 8 12 34 56 1 0 22 7
Array B
Swap 0 and (2 * 0 = 0) indexed elements
4 5 8 12 34 56 1 0 22 7
Swap 1 and 2 indexed elements
4 8 5 12 34 56 1 0 22 7
Swap 2 and 4 indexed elements
4 8 34 12 5 56 1 0 22 7
Swap 3 and 6 indexed elements
4 8 34 1 5 56 12 0 22 7
Swap 4 and 8 indexed elements
4 8 34 1 22 5 56 0 5 7
5 * 2 = 10 which exceeds the last index (9) of the array, so swapping stops.
Array C = Array A + Array B
= 8 13 42 13 56 61 6 0 27 14
Left half of array C = 8 13 42 13 56
Min = 8
If odd number of elements in array (size is an odd number then
left half= = (size+1)/2)
I just don't know how to input the characters at all, I tried cin with the arrays, but I remembered that's not how you input arrays. So now I'm at a loss again