Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //qastion 1
- #include<iostream>
- using namespace std;
- //the function to print arrays
- void print_array(int x[],int size)
- {
- cout<<"\nPrint array \n";
- for(int i=0;i<size;i++)
- {
- cout<<x[i]<<"\t";
- }
- }
- void add_x_y(int x[],int size1,int y[],int size2)
- {
- int z[3];
- for(int i=0;i<size1;i++)
- {
- z[i]=x[i+2];
- }
- for(int i=0;i<size2;i++)
- {
- z[i]+=y[i];
- }
- cout<<"\nArray of Z (y and last three element of x)\n";
- for(int i=0;i<3;i++)
- {
- cout<<z[i]<<"\t";
- }
- }
- int main()
- { //read two arrays
- int x[5],y[3],i;
- cout<<"Array of X \n";
- for(i=0;i<5;i++)
- {
- cout<<"["<<i+1<<"]";
- cin>>x[i];
- }
- cout<<"Array of Y \n";
- for(i=0;i<3;i++)
- {
- cout<<"["<<i+1<<"]";
- cin>>y[i];
- }
- //use a function to print the arrays (x and y)
- print_array(x,5);
- print_array(y,3);
- //find and print the smallest number in array (x)
- int mini=0;
- mini=x[0];
- for(i=0;i<5;i++)
- {
- if(x[i]<mini)
- {
- mini=x[i];
- }
- }
- cout<<"\nThe smallest number in array x : "<<mini<<endl;
- //add elemnt of array y with last three elements in array x
- add_x_y(x,5,y,3);
- }
Advertisement
Add Comment
Please, Sign In to add comment