Get premium membership and access questions with answers, video lessons as well as revision papers.

Write a C program that sorts an array of 10 numbers and swaps them starting from zero in ascending order

      

Write a C program that sorts an array of 10 numbers and swaps them starting from zero in ascending order.

  

Answers


Nyaundi
#include
#include

#define max 10

int list[max]={1,0,8,3,7,2,9,4,6,5};
void display(){
int i;
printf("[");

for(i=0;i printf("%d",list[i]);
}
printf("]\n");
}
void bubblesort(){
int i,j;
int temp;bool swapped=false;

for(i=0;i swapped =false;
for(j=0;j printf("\nitems compaired :[%d,%d]",list[j],list[j+1]);
if(list[j]>list[j+1]){
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
swapped=true;
printf("=> swapped [%d,%d]\n",list[j],list[j+1]);
}else
{
{
printf(" => not swapped\n");}

}
}
if(!swapped){
break;
}
printf("\nIteration %d :" , (i+1));
display();
}
}
int main()
{
printf("input array\n");
display();
printf("\n");
bubblesort();
display();
printf("\n\tOutput array is:");
display();
return 0;
}

rabin answered the question on November 20, 2017 at 09:34


Next: Use the map of Kenya below to answer questions below
Previous: Amoeba is a tiny ,one-celled organism.This diagram below shows the structure of a fresh water Amoeba as seen through a light microscope

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions