Write a program in C++ to short a array in ascending order.
#include<iostream.h>
#include<conio.h> void main() { int i,j,a[10],temp,n; clrscr(); cout<<”Enter the size of the array”; cin>>n; cout<<”Enter the array elements” for(i=0i<n;i++) { cin>>arr[i]; } for(i=0;i<n-1;i++) { for(j=0;j<=n-1;j++) { if(a[j+1]<a[j]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } cout<<”Sorted array are :-“; for(i=0i<n;i++) { cout<<a[i]; } getch(); } |