66 982
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #50601 in C++ for Umer

Question #50601
Suppose you have a main() with three local arrays, all the same size and type (say
float). The first two are already initialized to values. Write a function called
addarrays() that accepts the addresses of the three arrays as arguments; adds the contents
of the first two arrays together, element by element; and places the results in the
third array before returning. A fourth argument to this function can carry the size of the
arrays. Use pointer notation throughout; the only place you need brackets is in defining
the arrays.

Expert's answer
Program:
#include<iostream>
#include<string>
#define SIZE 10
 
using namespace std;
 
void addarrays(floatarr1[],float arr2[],float sum[],int n)
{
    int i;
    for (i=0;i<n;i++)
        sum[i]=arr1[i]+arr2[i];
}
 
int main()
{
    floatarr1[SIZE]={1,2,3,4,5,6,7,8,9,0},arr2[SIZE]={3,2,1,5,2,3,4,5,0,1},arr3[SIZE];
    int n=SIZE,i;
    addarrays(arr1,arr2,arr3,n);
    cout<<"Array 1:";
    for(i=0;i<n;i++)
        cout<<arr1[i]<<"";
    cout<<endl<<"Array2:";
    for(i=0;i<n;i++)
        cout<<arr2[i]<<"";
 
    cout<<endl<<"Array3:";
    for(i=0;i<n;i++)
        cout<<arr3[i]<<"";
 
    return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions