You are on page 1of 5

1.

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();
}

3.Program to arrange elements


using selection sort
#include<iostream.h>
#include<conio.h>
void selectionsort(int[],int);
void main()
{
clrscr();
int a[20],n;
cout<<"enter the size of the array\n";
cin>>n;
cout<<"enter the array\n";
for(int i=0;i<n;i++)
cin>>a[i];
selectionsort(a,n);
getch();
}
void selectionsort(int a[],int n)
{
int small,pos,temp;
for(int i=0;i<n-1;i++)
{
small=a[i];
pos=i;
for(int j=i+1;j<n;j++)
{
if(small>a[j])
{
small=a[j];
pos=j;
}
}
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
cout<<"array after this pass\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}

4.Program to find length,


compare and

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();
}

5.Program to delete an element from


array #include<iostream.h>
#include<conio.h>
void dlt(int [],int,int);

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();
}

You might also like