#include <conio.h>
using namespace std;
int main ()
{ int x;
int array [10], t;
for (x=0; x<10; x++)
{
cout << "Enter integer number: " << x+1<< endl;
cin >> array[x];
}
for (x=0; x<10; x++)
{
for (int y=0; y<9; y++)
{
if(array[y]>array[y+1])
{
t=array[y];
array[y]=array[y+1];
array[y+1]=t;
}
}
}
cout << "The integers in ascending order are : ";
for (x=0;x<10;x++)
{
cout <<"\n";
cout << array[x];
cout <<"\n";
}
cout << "The integers in dascending order are : ";
for (x=10; x>-1; x--)
{
cout <<"\n";
cout << array[x];
cout << endl;
}
int datasize,y;
double largest , smallest;
largest =array[0];
for (y=0; y<10; y++)
{ if (array[y]>largest)
largest=array[y];
}
cout << "Largest number is : " << largest << endl;
smallest =array[0];
for (y=0; y<10; y++)
{ if (array[y]<smallest)
smallest=array[y];
}
cout<<"The smallest number is : "<<smallest<<endl;
return 0;
}
http://www.tutorial4us.com/cpp-program/cpp-short-array-element-ascending-order
ReplyDelete