Question #38820

let array x={3,2,8,8} & y={4,1,3,5} write a code which a)add elements in x to y. b)raise each element of x to the power specified by elements in y.c)divide each element of y by elements in x. d)display product of each element in x by element y.

Expert's answer

#include <iostream>
using namespace std;
#include <cmath>
#include <conio.h>
int main(){
int x[] = {3, 2, 8, 8};
int y[] = {4, 1, 3, 5};
cout << "Array X = { ";
for(int i = 0; i < sizeof(x)/sizeof(int); i++){
cout << x[i] << ' ';
}
cout << "}";
cout << endl << "Array Y = { ";
for(int i = 0; i < sizeof(y)/sizeof(int); i++){
cout << y[i] << ' ';
}
cout << "}";
cout << endl;
//==================part A
int z[sizeof(x)/sizeof(int)];
for(int i = 0; i < sizeof(y)/sizeof(int); i++){
z[i] = x[i] + y[i];
}
cout << endl << "Array X + Y = { ";
for(int i = 0; i < sizeof(y)/sizeof(int); i++){
cout << z[i] << ' ';
}
cout << "}";
//==================part B
for(int i = 0; i < sizeof(y)/sizeof(int); i++){
z[i] = pow((double)x[i], (double)y[i]);
}
cout << endl << endl << "Array X^Y = { ";
for(int i = 0; i < sizeof(y)/sizeof(int); i++){
cout << z[i] << ' ';
}
cout << "}";
//==================part C
double d[2*sizeof(x)/sizeof(double)];
for(int i = 0; i < 2*sizeof(y)/sizeof(double); i++){
d[i] = (double)y[i]/x[i];
}
cout << endl << endl << "Array Y/X = { ";
for(int i = 0; i < 2*sizeof(y)/sizeof(double); i++) {
cout << d[i] << ' ';
}
cout << "}";
//================part D
for(int i = 0; i < sizeof(y)/sizeof(int); i++) {
z[i] = x[i] * y[i];
}
cout << endl << endl << "Array X*Y = { ";
for(int i = 0; i < sizeof(y)/sizeof(int); i++) {
cout << z[i] << ' ';
}
cout << "}";
cout << endl << endl;
getch();
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS