You're trying to print float
s using the %d
specifier, which is for integers. Try
printf("%f\n", a[i]);
instead.
Pergunta
void quicksort(float x[],int first,int last)
{
float temp;int j, pivot, i;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(x[i]<=x[pivot]&&i<last)
i++;
while(x[j]>x[pivot])
j--;
if(i<j){
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);
}
}
main()
{
float a[]={4.0,6.0,8.5,9.1,6,11.1,1.1};
//int len=6;
int len=7;
quicksort(a,0,len);
int i=0;
for(i=0;i<len;i++)
printf("%d\n",a[i]);
}
During run-time on code-blocks ,prints gibberish and the loop does not ends after 7 iterations the execution goes on until it gives segmentation fault at the end. compiling it with gcc on command line does not helps .
but runs fine on my codeforces custom test USING GNU C++ 4.7 ie it ends after printing gibberish for 7 times. but gives
Runtime error: exit code is 11
when using GNU C 4
How to resolve this ?
Solução 2
You're trying to print float
s using the %d
specifier, which is for integers. Try
printf("%f\n", a[i]);
instead.
Outras dicas
There are two issues with your code:
%f
, not %d
, and that covers the gibrrish part...