Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

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

Answer Attachments

Exams With Marking Schemes

Related Questions