
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Divide every element of one array by other array elements in C++ Program
In this tutorial, we are going to write a program that divides one array of elements by another array of elements.
Here, we are following a simple method to complete the problem. Let's see the steps to solve the problem.
Initialize the two arrays.
Iterate through the second array and find the product of the elements.
Iterate through the first array and divide each element with a product of the second array elements.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; void divideArrOneWithTwo(int arr_one[], int arr_two[], int n, int m) { int arr_two_elements_product = 1; for (int i = 0; i < m; i++) { if (arr_two[i] != 0) { arr_two_elements_product = arr_two_elements_product * arr_two[i]; } } for (int i = 0; i < n; i++) { cout << floor(arr_one[i] / arr_two_elements_product) << " "; } cout << endl; } int main() { int arr_one[] = {32, 22, 4, 55, 6}, arr_two[] = {1, 2, 3}; divideArrOneWithTwo(arr_one, arr_two, 5, 3); return 0; }
Output
If you run the above code, then you will get the following result.
5 3 0 9 1
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- Count array elements that divide the sum of all other elements in C++
- Divide a scalar value into every element of a masked Array in NumPy
- JAVA Program to Replace Element of Integer Array with Product of Other Elements
- Divide a scalar value into every element of a masked Array with __truediv__() in NumPy
- Divide every element of a masked Array into a scalar value with __rtruediv__() in NumPy
- Print array elements that are divisible by at-least one other in C++
- Program to find length of the largest subset where one element in every pair is divisible by other in Python
- Python program to copy all elements of one array into another array
- Divide masked array elements by a given scalar element and return arrays with Quotient and Remainder in NumPy
- Find the element that appears once in an array where every other element appears twice in C++
- Floor of every element in same array in C++
- Count elements that are divisible by at-least one element in another array in C++
- Divide a scalar value into every element of a masked Array and return the floor value in NumPy
- Divide every element of a masked Array into a scalar value and return the floor value in NumPy
- Maximum number by concatenating every element in a rotation of an array in C++

Advertisements