Advertisement
Haval1

Ass. Sarmad Exams

Apr 24th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     //Answer quastion 1 for B array (2D)
  6.     int a[6][4],i,j,k=1;
  7.     for(i=0;i<6;i++)
  8.     {
  9.         for(j=0;j<4;j++)
  10.         {
  11.             a[i][j]=k;
  12.             k++;
  13.         }
  14.         k--;
  15.        
  16.     }
  17.     //Answer quastion 2 for B array (2D)
  18.     for(i=0;i<6;i++)
  19.     {
  20.         for(j=0;j<4;j++)
  21.         {
  22.             cout<<a[i][j]<<"\t";
  23.         }
  24.         cout<<endl;
  25.     }
  26.     cout<<"************************************************\n";
  27.     //Answer quastion 1 for A array (1D)
  28.     int b[7],p=35;
  29.     for(i=0;i<7;i++)
  30.     {
  31.         b[i]=p;
  32.         p-=5;
  33.     }
  34.     //Answer quastion 2 for A array (1D)
  35.     for(i=0;i<7;i++)
  36.     {
  37.         cout<<b[i]<<"\t";
  38.     }
  39.     cout<<"\n************************************************\n";
  40.     //Answer quastion 3 Swap array A with last colomn
  41.     for(i=0;i<6;i++)
  42.     {
  43.         int temp=a[i][3];
  44.         a[i][3]=b[i];
  45.         b[i]=temp;
  46.     }
  47.     for(i=0;i<6;i++)
  48.     {
  49.         for(j=0;j<4;j++)
  50.         {
  51.             cout<<a[i][j]<<"\t";
  52.         }
  53.         cout<<endl;
  54.     }
  55.     cout<<"\n************************************************\n";
  56.     for(i=0;i<7;i++)
  57.     {
  58.         cout<<b[i]<<"\t";
  59.     }
  60.     cout<<"\n************************************************\n";
  61.     //Answer quastion 4 find the Avarage for second row
  62.     int sum=0,x=0;
  63.     for(j=0;j<4;j++)
  64.     {
  65.         if(a[1][j]%2==1)
  66.         {
  67.             sum+=a[1][j];
  68.             x++;
  69.         }
  70.     }
  71.     float av=sum/x;
  72.     cout<<"Avarage = "<<av;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement