Problem with Bubble Sort code
Can anyone please help me to fix the following code...
Code:
#include<stdio.h>
#include<conio.h>
#define PF printf
/*PROGRAM TO BUBBLE SORT & 'n'NUMBERS INPUT BY USER*/
void main()
{
int nos[200],temp[200];
int a =1,b=1;
int x;
PF("\n\t\t\tLISA'S NUMBER BUBBLE SORTER IN ASCENDING ORDER");
PF("\nHOW MANY NUMBERS : ");
scanf("%d",&x);
x = x+1;
while(a <x)
{
PF("\nEnter Number %d : ",a);
scanf("%d",&nos[a]);
a++;
}
PF("\nTHE ORIGINAL SET OF NUMBERS:-");
a =1;
while(a < x)
{
cprintf("\n%d",nos[a]);
a++;
}
a=1;
//////////////////////////Initiate sorting////////////////////////
b =1;
for(b=1;b<x;b++){
for(a =1; a<x;a++){
if(nos[a] > nos[a+1]){temp[a] = nos[a];nos[a] = nos[a+1];nos[a+1] = temp[a];}
}
}
getch(); a = 1;
cprintf("\nAFTER BUBBLE SORTING:-");
while(a <x){
cprintf("\n%d",nos[a]); a++;}
getch();
}
//////////////////END of Program///////////////////////////////////
Should I use the special no. "-1" somewhere to end the sort???:confused: