Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- //Answer quastion 1 for B array (2D)
- int a[6][4],i,j,k=1;
- for(i=0;i<6;i++)
- {
- for(j=0;j<4;j++)
- {
- a[i][j]=k;
- k++;
- }
- k--;
- }
- //Answer quastion 2 for B array (2D)
- for(i=0;i<6;i++)
- {
- for(j=0;j<4;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl;
- }
- cout<<"************************************************\n";
- //Answer quastion 1 for A array (1D)
- int b[7],p=35;
- for(i=0;i<7;i++)
- {
- b[i]=p;
- p-=5;
- }
- //Answer quastion 2 for A array (1D)
- for(i=0;i<7;i++)
- {
- cout<<b[i]<<"\t";
- }
- cout<<"\n************************************************\n";
- //Answer quastion 3 Swap array A with last colomn
- for(i=0;i<6;i++)
- {
- int temp=a[i][3];
- a[i][3]=b[i];
- b[i]=temp;
- }
- for(i=0;i<6;i++)
- {
- for(j=0;j<4;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl;
- }
- cout<<"\n************************************************\n";
- for(i=0;i<7;i++)
- {
- cout<<b[i]<<"\t";
- }
- cout<<"\n************************************************\n";
- //Answer quastion 4 find the Avarage for second row
- int sum=0,x=0;
- for(j=0;j<4;j++)
- {
- if(a[1][j]%2==1)
- {
- sum+=a[1][j];
- x++;
- }
- }
- float av=sum/x;
- cout<<"Avarage = "<<av;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement