(C++) Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
#include <iostream> using namespace std; void triple(int arr[], int length); int main() { int arr[] = {5, 9, 1, 0, 2, 6}, length = 6; cout << "original array: "; for (int i = 0; i < length; ++i) { cout << arr[i] << " "; } cout << endl; triple(arr, length); cout << "modified array: "; for (int i = 0; i < length; ++i) { cout << arr[i] << " "; } cout << endl; return 0; } void triple(int arr[], int length) { for (int i = 0; i < length; ++i) { arr[i] *= 3; } }
Get Answers For Free
Most questions answered within 1 hours.