Haval1

quastion 1

May 15th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. //qastion 1
  2. #include<iostream>
  3. using namespace std;
  4. //the function to print arrays
  5. void print_array(int x[],int size)
  6. {
  7.     cout<<"\nPrint array \n";
  8.     for(int i=0;i<size;i++)
  9.     {
  10.         cout<<x[i]<<"\t";
  11.     }
  12. }
  13. void add_x_y(int x[],int size1,int y[],int size2)
  14. {
  15.     int z[3];
  16.     for(int i=0;i<size1;i++)
  17.     {
  18.         z[i]=x[i+2];
  19.     }
  20.     for(int i=0;i<size2;i++)
  21.     {
  22.         z[i]+=y[i];
  23.     }
  24.     cout<<"\nArray of Z (y and last three element of x)\n";
  25.     for(int i=0;i<3;i++)
  26.     {
  27.         cout<<z[i]<<"\t";
  28.     }
  29. }
  30.  
  31.  
  32. int main()
  33. {   //read two arrays
  34.     int x[5],y[3],i;
  35.     cout<<"Array of X \n";
  36.     for(i=0;i<5;i++)
  37.     {
  38.         cout<<"["<<i+1<<"]";
  39.         cin>>x[i];
  40.     }
  41.     cout<<"Array of Y \n";
  42.     for(i=0;i<3;i++)
  43.     {
  44.         cout<<"["<<i+1<<"]";
  45.         cin>>y[i];
  46.     }
  47.     //use a function to print the arrays (x and y)
  48.     print_array(x,5);
  49.     print_array(y,3);
  50.     //find and print the smallest number in array (x)
  51.     int mini=0;
  52.     mini=x[0];
  53.     for(i=0;i<5;i++)
  54.     {
  55.         if(x[i]<mini)
  56.         {
  57.             mini=x[i];
  58.         }
  59.     }
  60.     cout<<"\nThe smallest number in array x : "<<mini<<endl;
  61.     //add elemnt of array y with last three elements in array x
  62.     add_x_y(x,5,y,3);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment