Pages

Tuesday 22 March 2011

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINTS THE SERIES LIKE
N .......5 4 3 2 1 0 1 2 3 4 5........N.
PROGRAM-:   
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n;
cout<<"enter the value of n";
cin>>n;
for(i=n;i>=0;i--)
{
cout<<i;
}
for(i=1;i<=n;i++)
{
cout<<i;
}
getch();
}

Monday 21 March 2011

PROGRAM TO CONVERT DECIMAL NUMBER TO BINARY

DESCRIPTION-:This program receive input as decimal number and then calculate its binary equivalent and then display the binary equivalent of that decimal number.
FOR EXAMPLE-:If we have input decimal number------
                                          23
Then it generate output as-----------------
                                       10111
                           
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=0,j,d,a[10];
cout<<"enter the decimal number";
cin>>d;
while(d>0)
{
a[i]=d%2;
d=d/2;
i++;
}
cout<<"its binary equivalent is";
for(j=i-1;j>=0;j--)
{
cout<<a[j];
}
getch();
}

Saturday 19 March 2011

PROGRAM TO CALCULATE THE SUM OF EACH ROW AND EACH COLUMN AND TOTAL OF ALL ELEMENTS OF MATRIX

DESCRIPTION-: This program take matrix as input and again generate matrix as output in which sum of each row elements is placed in corrosponding row and also sum of each column elements is placed in corrosponding column and also calculate the total of all elements.
FOR EXAMPLE-:
If we have input matrix as-----

              2   3
              1   5

Then it generate output as--------

              2   3   5
              1   5   6
              3   8   11

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"enter the row and column of matrix";
cin>>m>>n;
cout<<"enter elements of array"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
a[i][n]=0;
for(j=0;j<n;j++)
{
a[i][n]=a[i][n]+a[i][j];
}
}
for(j=0;j<n;j++)
{
a[m][j]=0;
for(i=0;i<m;i++)
{
a[m][j]=a[m][j]+a[i][j];
}
}
a[m][n]=0;
for(i=0;i<m;i++)
{
a[m][n]=a[m][n]+a[i][n];
}
cout<<"\n";
for(i=0;i<m+1;i++)
{
cout<<"\n";
for(j=0;j<n+1;j++)
{
cout<<a[i][j]<<"\t";
}
}
getch();
}

PROGRAM TO FIND THE TRANSPOSE OF GIVEN MATRIX

DESCRIPTION-: This program takes matrix as input and then calculate the transpose of input matrix and after calculating transpose of matrix it generate output matrix.
FOR EXAMPLE-: If we have input matrix as--------

                                1   3   6
                                5   9   2
                                4   1   7

Then program generate output as---------

                                1   5   4
                                3   9   1
                                6   2   7


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,m,n,a[10][10],b[10][10];
cout<<"enter the number of rows and column of matrix"<<"\n";
cin>>m>>n;
cout<<"enter the value of elements of matrix";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"entered matrix is"<<"\n";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
}
cout<<"\n transpose of matrix is"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[i][j]=a[j][i];
}
}
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<m;j++)
{
cout<<b[i][j]<<"\t";
}
}
getch();
}

PROGRAM TO MULTIPLY TWO MATRICES

DESCRIPTION-: This program takes two matrices as input then calculate the multiplication of input  matrices and then generate the output matrix.The output matrix contains the multiplication of input matrices.
FOR EXAMPLE-:

If we have two input matrices as---------

              2   1                                       3   1   2
              1   3                                       1   2   3
              3   1
Then program generate output as--------
                      7   4   7
                      6   7   11
                     10  5   9

PROGRAM-:
#include<iostream.h> 
#include<conio.h>
void main()
{
clrscr();
int i,j,m,n,p,q,a[10][10],b[10][10],c[10][10];
cout<<"enter row and column of matrix A";
cin>>m>>n;
cout<<"\n enter the row and column of matrix B";
cin>>p>>q;
if(n!=p)
{
cout<<"multiplication not possible";
}
else
{
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter values of elements of matrix B"<<"\n";

for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"multiplication  of two matrix is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
{
c[i][j]=0;
for(int k=0;k<p;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout<<c[i][j]<<"\t";
}
 }
}
getch();
}

PROGRAM TO SUBTRACT TWO MATRIX

DESCRIPTION- This program takes two matrices as input and then generate the output matrix after subtracting the two input matrices.The order of input matrix must be same.
FOR EXAMPLE-: If we have two input  matrices as---------

             2   3   1                                 2   2   1
             1   5   7                                 1   4   6
             2   8   1                                 1   3   1

Then program generate output as---------
                                  0   1   0
                                  0   1   1
                                  1   5   0

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,a[10][10],b[10][10],c[10][10];
cout<<"enter the order of matrix A";
cin>>n;
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the order of matrix B";
cin>>n;
cout<<"enter values of elements of matrix B"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"subtraction of matrix A and B is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

PROGRAM TO ADD TWO MATRIX

DESCRIPTION-:This program takes two matrices as input and then generate the output matrix which contain the addition of two input matrices.The order of two input matrices must be same.
FOR EXAMPLE-:  If we have two input matrices as-------
               2   6   1                           2   1   5
               3   1   3                           7   2   1
               1   0   5                           1   7   0


Then program generate output as-------
                                     4   7   6

                                    10  3   4
                                     2   7   5

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,a[10][10],b[10][10],c[10][10];
cout<<"enter the order of matrix A";
cin>>n;
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the order of matrix B";
cin>>n;
cout<<"enter values of elements of matrix B"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"addition of matrix A and B is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}
 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.