# include<iostream.h>
# include<conio.h>
# include<stdlib.h>
int main()
{
int i,j,n,pos,k,size,sear,temp;
int a[15];
clrscr();
cout<<"\n Enter the array size\t";
cin>>size;
cout<<"\n Enter the element to search\t";
cin>>sear;
cout<<"\n Enter the\t "<<size<<"\telements\n";
for (i=1;i<=size;i++)
{
cin>>a[i];
}
cout<<"\nGiven Elemnts are\n";
for (i=1;i<=size;i++)
{
cout<<a[i]<<"\t";
}
for (i=1;i<=size;i++)
{
if (a[i]==sear)
{
pos=i;
k=1;
break;
}
else
{
k=0;
continue;
}
}
if (k==1)
cout<<"\n"<<sear<<"\t is available in the array & its position is\t"<<pos;
else
cout<<sear<<"\n is not available in the array";
// ascending order
for (i=1;i<=size;i++){
for(j=i+1;j<=size;j++){
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
// printing in ascending order
cout<<"\n ASCENDING ORDER\n ";
for (i=1;i<=size;i++)
{
cout<<"\t"<<a[i];
}
// descending order
cout<<"\n DESCENDING ORDER\n ";
for (i=size;i>=1;i--)
{
cout<<"\t"<<a[i];
}
return(0);
}
# include<conio.h>
# include<stdlib.h>
int main()
{
int i,j,n,pos,k,size,sear,temp;
int a[15];
clrscr();
cout<<"\n Enter the array size\t";
cin>>size;
cout<<"\n Enter the element to search\t";
cin>>sear;
cout<<"\n Enter the\t "<<size<<"\telements\n";
for (i=1;i<=size;i++)
{
cin>>a[i];
}
cout<<"\nGiven Elemnts are\n";
for (i=1;i<=size;i++)
{
cout<<a[i]<<"\t";
}
for (i=1;i<=size;i++)
{
if (a[i]==sear)
{
pos=i;
k=1;
break;
}
else
{
k=0;
continue;
}
}
if (k==1)
cout<<"\n"<<sear<<"\t is available in the array & its position is\t"<<pos;
else
cout<<sear<<"\n is not available in the array";
// ascending order
for (i=1;i<=size;i++){
for(j=i+1;j<=size;j++){
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
// printing in ascending order
cout<<"\n ASCENDING ORDER\n ";
for (i=1;i<=size;i++)
{
cout<<"\t"<<a[i];
}
// descending order
cout<<"\n DESCENDING ORDER\n ";
for (i=size;i>=1;i--)
{
cout<<"\t"<<a[i];
}
return(0);
}
No comments:
Post a Comment