Professional Documents
Culture Documents
1.program To Show Transpose of Matrix Using Array
1.program To Show Transpose of Matrix Using Array
1.program To Show Transpose of Matrix Using Array
Program to show
transpose of Matrix
Using Array
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m[3][3],n[3][3],c,d;
cout<<"Enter the array \n";
for(c=0;c<3;c++)
for(d=0;d<3;d++)
cin>>m[c][d];
cout<<Matrix is<<endl;
for(c=0;c<3;c++)
{
for(d=0;d<3;d++)
cout<<m[c][d]<<'\t';
cout<<"\n";
}
for(c=0;c<3;c++)
for(d=0;d<3;d++)
n[c][d]=m[d][c];
cout<<"Transpose of the matrix is\n";
for(c=0;c<3;c++)
{
for(d=0;d<3;d++)
cout<<n[c][d]<<'\t';
cout<<"\n";
}
getch();
}
2.Program to show
elements which
are divisible by
2 and 5 both
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],i,j,r,c;
cout<<"enter the no. of rows and column\n";
cin>>r>>c;
cout<<"enter the elements of the array\n";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
cin>>a[i][j];
cout<<"elements divisible by 2 and 5 both are\n";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if(a[i][j]%10==0)
cout<<a[i][j]<<'\n';
}
getch();
}
concatenate two
strings
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50],b[50];
int l1,l2,l3;
cout<<"enter both the strings\n";
gets(a);
gets(b);
l1=strlen(a);
l2=strlen(b);
cout<<"length of first string"<<l1<<'\n';
cout<<"length of second string"<<l2<<'\n';
if(l1>l2)
cout<<"first string is greater\n";
else if(l2>l1)
cout<<"second string is greater\n";
else
cout<<"both strings are equal\n";
cout<<"string after concatenation is \n"<<strcat(a,b);
getch();
}
void main()
{
clrscr();
int a[50],i,n,e;
cout<<"enter the no. of elements to be entered\n";
cin>>n;
cout<<"enter the elements in the array\n";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter the element you want to delete\n";
cin>>e;
dlt(a,n,e);
}
void dlt(int a[],int n,int e)
{
int p;
for(int i=0;i<n;i++)
{
if(a[i]==e)
p=i;
}
for(i=p;i<n;i++)
{a[i]=a[i+1];
}
n--;
cout<<"New array is\n";
for(i=0;i<n;i++)
cout<<a[i]<<'\t';
getch();
}