Haval1

quastion 1 for 2016 exam

May 23rd, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //W.P to input data into the array A[3][3] and find the average of the positive values in the second column and first row together
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a[3][3],i,j;
  7.     for(i=0;i<3;i++)
  8.     {
  9.         for(j=0;j<3;j++)
  10.         {
  11.             cout<<"["<<i<<"]["<<j<<"]";
  12.             cin>>a[i][j];
  13.         }
  14.     }
  15.     for(i=0;i<3;i++)
  16.     {
  17.         for(j=0;j<3;j++)
  18.         {
  19.             cout<<a[i][j]<<"\t";
  20.         }
  21.         cout<<endl<<endl;
  22.     }
  23.     int k=0,sum=0;
  24.     for(j=0;j<3;j++)
  25.     {
  26.         if(a[j][1]&&a[0][j]>0)
  27.         {
  28.             sum+=a[0][j]+a[j][1];
  29.             k++;
  30.         }
  31.     }
  32.     cout<<"sum = "<<sum;
  33.     if(k==0)
  34.     {
  35.         cout<<"\nNot Found Positive Number\n";
  36.     }
  37.     else if(k!=0){
  38.         float av=sum/k;
  39.         cout<<"Av = "<<av;
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment