Answer to Question #286366 in C++ for A lawal

Question #286366

write a program to sort an integer of size 5 in ascending order using a burble sort algorithm



1
Expert's answer
2022-01-10T13:53:29-0500
using namespace std;






// write a program to sort an integer of size 5 in ascending order using a burble sort algorithm


void swap(int *p,int *q) 
{
   unsigned int t;   
   t=*p; 
   *p=*q; 
   *q=t;
}


void sort(int a[],int n) 
{ 
   int i,j;
   int temp;


   for(i = 0;i < n-1;i++) 
   {
      for(j = 0;j < n-i-1;j++) 
	  {
         if(a[j] > a[j+1])	swap(&a[j],&a[j+1]);
      }
   }
    cout<<"\nThe sorted numbers are: ";
    for(i = 0;i < n;i++) cout<<a[i]<<", ";
//    for(i = n-1;i >=0;i--) cout<<a[i]<<", ";


}


main(void)
{
	int Num[5];
	int n=0,a;
	
	cout<<"\nEnter five integers separated by space: "; 
	for(n=0;n<5;n++) cin>>Num[n];


	sort(&Num[0],5);
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment