PLEASE ANSWER THE QUESTION WITHIN 20 MINUTES AS THE SUBMISSION DEADLINE IS TILL
ID: 3740317 • Letter: P
Question
PLEASE ANSWER THE QUESTION WITHIN 20 MINUTES AS THE SUBMISSION DEADLINE IS TILL THEN
WRITE C++ PROGRAM FOR THE FOLLOWING USING*1D Array and Functions
A)Write a function ArrayDistance that takes two arrays array_one and array_two of equal size and returns their Euclidean distance Where ?? is the size of arrays Example: ??=[??,??,??,??,??,??,??,??] ?????? ??=[??,??,??,??,??,??,??,??] ??????? ?????????? ???????????????? ???? ??.????????
b) Write a function Sum_Initials that takes first two elements of arrays array_1 and array_2 and returns their sum. (5 points)
For example
array_1 = [1 5 6 8 2 1 3 2 ]
array_2 = [1 8 4 2 2 9 3 7 ]
Output = 1 + 5 + 1 + 8 = 15
Explanation / Answer
A) Hi, I did not get example you have given.Please clarify so that the answer can be provided.
B) Following is the code:
#include <iostream>
#include<conio.h>
using namespace std;
int sum_Initials(int array11,int array12,int array21,int array22)
{
return array11 + array12 + array21 + array22;
}
int main()
{
int n1,n2;
int sum;
cout<<"Enter size of array1 "<<endl;
cin>>n1;
cout<<"Enter size of array2 "<<endl;
cin>>n2;
if(n1 >= 2 && n2>=2) { // not possible for arrays with size less than 2
int array1[n1], array2[n2];
cout<<"Enter elements of first array "<<endl;
for(int i=0; i<n1; i++) {
cin>>array1[i];
}
cout<<"Enter elements of second array "<<endl;
for(int i=0; i<n2; i++) {
cin>>array2[i];
}
sum = sum_Initials(array1[0],array1[1], array2[0], array2[1]); //calling distanceCalculate formula
cout<<"Sum is: "<<sum;
} else {
cout<<"Size of both arrays must be more than 2";
}
}
Feel free to ask questions, if any and don't forget to rate, if it solves your query :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.