#include<iostream.h>
#include<conio.h>
class Array
{
private:
int a[10];
pulic:
void getArray();
void sortArray();
void printArray();
};
void Array::getArray()
{
for(int i=0;i<10;i++)
{
cout<<"Enter the"<<i+1<<"th Element";
cin>>a[i];
}
}
void Array::printArray()
{
for(int i=0;i<10;i++)
cout<<"The"<<i+1<<"th Element is"<<a[i]<<"\n";
}
void Array::sortArray()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(a[j]>a[i])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void main()
{
Array A;
clrscr();
A.getArray();
A.sortArray();
A.printArray();
getch();
}
Output:
Enter the 1th Element78
Enter the 2th Element23
Enter the 3th Element1
Enter the 4th Element100
Enter the 5th Element45
Enter the 6th Element6
Enter the 7th Element19
Enter the 8th Element2
Enter the 9th Element17
Enter the 10th Element18
The 1th Element is 1
The 2th Element is 2
The 3th Element is 6
The 4th Element is 17
The 5th Element is 18
The 6th Element is 19
The 7th Element is 23
The 8th Element is 45
The 9th Element is 78
The 10th Element is 100
#include<conio.h>
class Array
{
private:
int a[10];
pulic:
void getArray();
void sortArray();
void printArray();
};
void Array::getArray()
{
for(int i=0;i<10;i++)
{
cout<<"Enter the"<<i+1<<"th Element";
cin>>a[i];
}
}
void Array::printArray()
{
for(int i=0;i<10;i++)
cout<<"The"<<i+1<<"th Element is"<<a[i]<<"\n";
}
void Array::sortArray()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(a[j]>a[i])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void main()
{
Array A;
clrscr();
A.getArray();
A.sortArray();
A.printArray();
getch();
}
Output:
Enter the 1th Element78
Enter the 2th Element23
Enter the 3th Element1
Enter the 4th Element100
Enter the 5th Element45
Enter the 6th Element6
Enter the 7th Element19
Enter the 8th Element2
Enter the 9th Element17
Enter the 10th Element18
The 1th Element is 1
The 2th Element is 2
The 3th Element is 6
The 4th Element is 17
The 5th Element is 18
The 6th Element is 19
The 7th Element is 23
The 8th Element is 45
The 9th Element is 78
The 10th Element is 100
No comments:
Post a Comment