Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that will select the biggest number in an array and put it firs

ID: 3773656 • Letter: W

Question

Write a function that will select the biggest number in an array and put it first position at the right.This is the array: int v[]={1,9,4,10,7,3,6,2,14,13,8};they want us to select 14 in the array and place it after 8.This function should not sort the whole of the array but can only change the order of the array so we har this result: output:1,4,9,7,3,6,2,10,13,8,14, Rewrite this code below to achieve the result. #include void bubbla(int v[],int n){ //write you code here. }int main(void){ int v[]={1,9,4,10,7,3,6,2,14,13,8}; bubbla(v,11); for(int i=0;i<11;i++) printf("%d,",v[]); return 0; } NB:Use bubble sort technique in your C code.

Explanation / Answer

#include <iostream>
#include <conio.h>
using namespace std;

void bubbla(int v[],int n)
{
   /*find max value in the array and corrosponding position of the element*/
   int max=0,pos;
   /*Set the first value as max value*/
   max=v[0];
   for(int i=1;i<n;i++)
   {
       if(max<v[i])
       {
           max=v[i];
           pos=i;
       }
   }
   /*keep the max value 14, to the extreem right*/
   for(int b=pos;b<n-1;b++)
   {
       /*Swap the elements to get the max element as last element*/
       int temp= v[b+1];
       v[b+1]= v[b];
       v[b]= temp;
   }
}
int main(void)
{
   int v[]={1,9,4,10,7,3,6,2,14,13,8};
   bubbla(v,11);
   for(int i=0;i<11;i++)
       printf("%d,",v[i]);
   return 0;  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote