7 работа с указателями и
Download 152.84 Kb. Pdf ko'rish
|
17 7
ТЕМА:7 РАБОТА С УКАЗАТЕЛЯМИ И ДИНАМИЧЕСКОЙ ПАМЯТЬЮ Сделал: Худаяров Хокимжон #include using namespace std; int* removeMultipleOfThree(int* arr, int& size) { int* newArr = new int[size]; int newSize = 0; for (int i = 0; i < size; i++) { if (arr[i] % 3 != 0) { newArr[newSize] = arr[i]; newSize++; } } size = newSize; return newArr; } int main() { int size = 10; int* arr = new int[size]; int a = -30, b = 30; srand(time(NULL)); for (int i = 0; i < size; i++) { arr[i] = a + rand() % (b - a + 1); } cout << "Original array: "; for (int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; arr = removeMultipleOfThree(arr, size); cout << "Modified array: "; for (int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; delete[] arr; return 0; } Download 152.84 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling