Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (1)
- Matrix Sum of Rows and Coloumns
- #include<iostream.h>
- #include<conio.h>
- void sum(int a[][20],int m,int n)
- {
- int i,j,s=0;
- for(i=0;i<m;i++)
- {
- s=0;
- for(j=0;j<n;j++)
- s+=a[i][j];
- cout<<"\nSum of"<<i<<"row"<<s;
- }
- for(i=0;i<m;i++)
- {
- s=0;
- for(j=0;j<n;j++)
- s+=a[j][i];
- cout<<"\nSum of"<<i<<"coloumn"<<s;
- }
- }
- void main()
- {
- int a[10][20],m,n,i,j;
- cout<<"Enter the order of matrix";
- cin>>m>>n;
- cout<<"Enter the Elements";
- for(i=0;i<m;i++)
- for(j=0;j<n;j++)
- cin>>a[i][j];
- sum(a,m,n);
- getch();
- }
- (2)
- Program to find sum of diagonals in a matrix
- #include<iostream.h>
- #include<conio.h>
- int sod(int a[10][10],int r,int c)
- {
- int i,j,sum=0;
- for(i=0;i<r;i++)
- {
- for(j=0;j<c;j++)
- {
- if(i==j||i+j==r-1)
- sum+=a[i][j];
- }
- }
- return(sum);
- }
- void main()
- {
- clrscr();
- int a[10][10],r,c,i,j;
- cout<<"\n";
- cout<<"enter size of row and column ";
- cout<<"\n";
- cin>>r>>c;
- cout<<"\n";
- cout<<"enter elements";
- for(i=0;i<r;i++)
- {
- cout<<"\n";
- for(j=0;j<c;j++)
- {
- cin>>a[i][j];
- }
- }
- cout<<"\n";
- cout<<"sum is"<< sod(a,r,c);
- getch();
- }
- (3)
- Program for Matrix Multiplication
- #include<iostream.h>
- #include<conio.h>
- void mul(int a[10][10],int b[10][10],int c[20][20],int d,int r,int r1,int c1);
- void main()
- {
- clrscr();
- int a[10][10],b[10][10],c[20][20],r,d,i,j,r1,c1;
- cout<<"\n";
- cout<<"enter size row and column of matix 1";
- cout<<"\n\n";
- cin>>r;
- cout<<"\n";
- cin>>d;
- cout<<"\n";
- cout<<"enter elements";
- cout<<"\n";
- for(i=0;i<r;i++)
- {
- for(j=0;j<d;j++)
- {
- cout<<"\n";
- cin>>a[i][j];
- }
- }
- cout<<"\n";
- cout<<"enter size of row and column of matix 2";
- cout<<"\n\n";
- cin>>r1;
- cout<<"\n";
- cin>>c1;
- cout<<"\n";
- cout<<"enter elements in matrix 2";
- cout<<"\n";
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c1;j++)
- {
- cout<<"\n";
- cin>>b[i][j];
- }
- }
- mul(a,b,c,d,r,r1,c1);
- getch();
- }
- void mul(int a[10][10],int b[10][10],int c[20][20],int d,int r,int r1,int c1)
- {
- int k,i,j;
- if(d!=r1)
- {
- cout<<"multiplication not possible";
- }
- else
- {
- for(i=0;i<r;i++)
- {
- for(j=0;j<c1;j++)
- {
- for(k=0;k<r1;k++)
- {
- c[i][j]+=a[i][k]*b[k][j];
- }
- }
- }
- }
- cout<<"\n";
- cout<<"after multiplication"<<"\n\n";
- for(i=0;i<r;i++)
- {
- for(j=0;j<c1;j++)
- {
- cout<<c[i][j]<<"\t";
- }
- }
- }
- (4)
- Program to display numbers divisible by 10 in a Matrix
- #include<iostream.h>
- #include<conio.h>
- void disp(int m[5][5]);
- void main()
- {
- clrscr();
- int m[5][5],i,j;
- cout<<"\n\n";
- cout<<"enter elements";
- cout<<"\n";
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- cout<<"\n";
- cin>>m[i][j];
- }
- }
- disp(m);
- getch();
- }
- void disp(int m[5][5])
- {
- int i,j;
- cout<<"\n\n";
- cout<<"nos. divisible by 10 are";
- cout<<"\n\n";
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- if(m[i][j]%10==0)
- {
- cout<<m[i][j]<<"\t";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment