Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ArrAdSubMul
//g++ 7.4.0 //write and test functions that add, subtract and multiply element-wise 2 one-dimensional int arrays of the same size //this code is created by Rezaul Hoque on June 21,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int m=6, n=6; int add(int [],int [],int , int ); int sub(int [], int [], int, int); int mul(int [], int [], int, int); int add(int a[],int b[],int m , int n){ int c[m]={0,0,0,0,0,0};//resultant array to hold the sum of a[] and b[] int i; for(i=0;i<m;i++) c[i]=a[i]+b[i]; for(i=0;i<m;i++) cout<<" "<<c[i]; } int sub(int a[],int b[],int m , int n){ int d[m]={0,0,0,0,0,0};//resultant array to hold differences between a[] and b[] int i; for(i=0;i<m;i++) d[i]=a[i]-b[i]; for(i=0;i<m;i++) cout<<" "<<d[i]; } int mul(int a[],int b[],int m , int n){ int e[m]={1,1,1,1,1,1};//resultant array to hold the product of a[] and b[] int i; for(i=0;i<m;i++) e[i]=a[i]*b[i]; for(i=0;i<m;i++) cout<<" "<<e[i]; } int main() { int a[m]={7,6,5,4,3,2}; int b[n]={1,2,3,4,5,1}; cout<<"Array holding sum of a and b:\n"<<add(a,b,m,n)<<"\n"; cout<<"Array holding differences between a and b:\n"<<sub(a,b,m,n)<<"\n"; cout<<"Array holding product of a and b:\n"<<mul(a,b,m,n)<<"\n"; return 0; }
run
|
edit
|
history
|
help
0
Org
Geometric Series
sd2
Nobita's candies problem
Widget Class with dynamic memory and pointers
cache_node.cc
ProPriceTemp
LRU - DLL
Shuffle algorithm
Goooood