
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Count array elements that divide the sum of all other elements in C++
- Print array elements that are divisible by at-least one other in C++
- Divide a scalar value into every element of a masked Array in NumPy
- Floor of every element in same array in C++
- Find the element having different frequency than other array elements in C++
- Count elements that are divisible by at-least one element in another array in C++
- Maximum number by concatenating every element in a rotation of an array in C++
- Find the element that appears once in an array where every other element appears twice in C++
- Program to find length of the largest subset where one element in every pair is divisible by other in Python
- Find original array from encrypted array (An array of sums of other elements) using C++.
- Elements of an array that are not divisible by any element of another array in C++
- 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
- Maximum possible XOR of every element in an array with another array in C++
- Python program to copy all elements of one array into another array
Advertisements