C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++

I have a sample code but I need someone who can explain me step by step this code in comment please https://drive.google.com/file/d/17268Cr9fNkwY6EXc8o-CNgTr-oFWA_MT/view?usp=drivesdk

5th Jun 2022, 12:39 PM
Daniel Alexis
6 Answers
0
can send the code here
5th Jun 2022, 12:51 PM
ZAKI MAX
ZAKI MAX - avatar
0
the code is a little too long, Sololearn does not want to accept it
5th Jun 2022, 1:04 PM
Daniel Alexis
0
Unless I send it in two parts
5th Jun 2022, 1:04 PM
Daniel Alexis
0
I can't open the link
5th Jun 2022, 1:07 PM
ZAKI MAX
ZAKI MAX - avatar
0
#include <iostream> using namespace std; void init(int inputSize); int main() { int size; cout << "Введите размер массива: "; cin >> size; init(size); } void init(int inputSize) { int outputSize, i; outputSize = inputSize % 2 == 0 ? inputSize * 2 : inputSize * 2 - 1; int* input = new int[inputSize]; int* output = new int[outputSize]; int* ptr, *offsetPtr, *endPtr; for (ptr = input, i = 0; ptr < &input[inputSize]; ptr++, i++) { cout << "a[" << i << "] = "; cin >> input[i]; } for (endPtr = &output[outputSize], ptr = input, offsetPtr = output, i = 0; ptr < &input[inputSize]; ptr++, i++) { if (i % 2 == 0 && i != 0) { offsetPtr = offsetPtr + 2; } *offsetPtr = *ptr; if ((offsetPtr + 2) < endPtr) { *(offsetPtr+2) = *ptr; } offsetPtr++; } for (ptr = input; ptr < &input[inputSize]; ptr++) { cout << *ptr; } cout << " —> "; delete[] input; for (ptr = output; ptr < &output[outputSize]; ptr++) { cout <<" " <<*ptr << " "; } delete[] output; }
5th Jun 2022, 1:07 PM
Daniel Alexis
0
here👆
5th Jun 2022, 1:08 PM
Daniel Alexis