Haval1

Rotate first Row a[3][3] whith c[3] array using function

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