Write a C++ function that takes a pointer to an array of
integers as a parameter and return the number of prime integers in
the array. Write main() program to test the function.
#include <iostream> #include <cstdlib> using namespace std; int count_primes(int *arr, int size) { int count = 0, n; bool is_prime; for (int i = 0; i < size; ++i) { n = arr[i]; is_prime = n > 1; for (int j = 2; j < n; ++j) { if (n % j == 0) { is_prime = false; } } if (is_prime) ++count; } return count; } int main() { int size; cout << "Enter size of array: "; cin >> size; cout << "Enter " << size << " integers: "; int *arr = new int[size]; for (int i = 0; i < size; ++i) { cin >> arr[i]; } int count = count_primes(arr, size); cout << "Number of primes in array is " << count << endl; return 0; }
Write a C++ function that takes a pointer to an array of integers as a parameter...
Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.
Write a C++ program which inputs an array of integers from user then pass array pointer to function which will return sum of whole array. Also do same action by using address-based argument of array to another function. Note: In this you need to declare two factions: 1. With argument of pointer type. 2.With argument type of address type
C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that...
(C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...
PYHTON Write a function which takes a single parameter. The parameter is a list of integers. Your function should return a count of the number of integers in the list which are odd
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...
please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...
Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates all the duplicate integer integers in the array. The function should take two arguments: (1) an array of integers; (2) an integer that tells the number of cells in the array. The function should return the number of distinct integers in the array.
Write a C++ function that takes a two-dimensional array and a row index. The function should return the multiplication of all the values in the row. Write a main () program to test the function. Student Note: Please solve the question as simple as you can.