Advertisement
Haval1

change upper half c[4][4] with lower half e[4][4] using fun.

May 22nd, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. //W.P to change upper half of D[4][4] with the lower half of E[4][4] Use "function" statement.
  2. #include<iostream>
  3. using namespace std;
  4. void print_array(int a[][4],int x,int y)
  5. {
  6.     for(int i=0;i<x;i++)
  7.     {
  8.         for(int j=0;j<y;j++)
  9.         {
  10.             cout<<a[i][j]<<"\t";
  11.         }
  12.         cout<<endl<<endl;
  13.     }
  14.     cout<<"------------------------------------\n";
  15. }
  16. void change(int a[][4],int x,int y,int b[][4],int r,int c)
  17. {   int k[4][4],i,j;
  18.     for(i=0;i<x-2;i++)
  19.     {
  20.         for(j=0;j<y;j++)
  21.         {
  22.             k[i][j]=a[i][j];
  23.             a[i][j]=b[i+2][j];
  24.             b[i+2][j]=k[i][j];
  25.         }
  26.     }
  27. }
  28. int main()
  29. {
  30.     int c[4][4],e[4][4],i,j;
  31.     cout<<"Input for c[][] array\n";
  32.     for(i=0;i<4;i++)
  33.     {
  34.         for(j=0;j<4;j++)
  35.         {
  36.             cout<<"["<<i<<"]["<<j<<"]";
  37.             cin>>c[i][j];
  38.         }
  39.     }
  40.     cout<<"\nInput for E[][] array\n";
  41.     for(i=0;i<4;i++)
  42.     {
  43.         for(j=0;j<4;j++)
  44.         {
  45.             cout<<"["<<i<<"]["<<j<<"]";
  46.             cin>>e[i][j];
  47.         }
  48.     }
  49.     print_array(c,4,4);
  50.     print_array(e,4,4);
  51.     change(c,4,4,e,4,4);
  52.     print_array(c,4,4);
  53.     print_array(e,4,4);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement