Lecture 66
// Loop For
#include <iostream>
#include <conio.h>
using namespace std;
main ()
{
int n,a[5];
cout<<"Initialisation array:\n ";
for(n=0;n<5;n++)
{
cout<<"Enter the number: ";
cin>>a[n];
}
cout<<"Print
the array :\n";
for(n=0;n<5;n++)
{
cout<<a[n]<<endl;
}
cout<<"Print the sort array :\n";
int i,j,a1;
for(
i=0;i<5;i++)
for(j=i;j<5;j++)
{
if(a[i]>a[j])
{
a1=a[i];
a[i]=a[j];
a[j]=a1;
}
}
for(n=0;n<5;n++)
{
cout<<a[n]<<endl;
}
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10