- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum Sum of Products of Two Arrays in C++
In this tutorial, we will be discussing a program to find maximum Sum of Products of Two Arrays.
For this we will be provided with two arrays of same size. Our task is to find the maximum sum by multiplying exactly one element from first element with one element from the second array.
Example
#include<bits/stdc++.h> using namespace std; //calculating maximum sum by //multiplying elements int maximumSOP(int *a, int *b) { int sop = 0; int n = sizeof(a)/sizeof(a[0]); sort(a,a+n+1); sort(b,b+n+1); for (int i = 0; i <=n; i++) { sop += a[i] * b[i]; } return sop; } int main() { int A[] = { 1, 2, 3 }; int B[] = { 4, 5, 1 }; cout<<maximumSOP(A, B); return 0; }
Output
24
Advertisements