# Thread: Help in converting float instead of int in quicksort program

1. ## Help in converting float instead of int in quicksort program

for example you are asked to input 10 numbers e.g. 1.23, 7.453, 45.7, 345 etc how are you going to convert these floats into int

I would like to use them with quicksort without using #include <stdlib.h>

Thanks!

2. Why do you need to convert them to int? Shouldn't your implementation of quicksort handle these numbers as float or double?

3. I believe multiply the number by 100 or 1000 is the answer. Then divide by int 1 to get rid of any extra digits after the decimal place.

4. cause the program i made was using int and i have problems in converting it where floats are involved

5. Originally Posted by Bebi
cause the program i made was using int and i have problems in converting it where floats are involved
Then you should resolve those problems instead of coming up with an incorrect program by trying to convert those numbers to int. So, what are the problems that you face?

6. laserlight is the solution proposed by adak acceptable? just looking for a 2nd opinion. thanks a lot

7. Originally Posted by Bebi
laserlight is the solution proposed by adak acceptable?
Adak's solution is designed to work on your example input, but is your example input truly representative of the actual input to your program? For example, can 1.111111 and 1.111122 be entered as input? If so, would you consider them to be equal?

8. Generally speaking, you don't want to convert a float to an int - that's why the variable is a float in the first place - you need that string of digits after the decimal place.

You don't need to include stdlib to use Quicksort - quicksort is an algorithm apart from qsort() in the standard library.

post up your problem, and let's see about doing it right - my answer may be "correct", for the exact question you asked, but it's also, almost always wrong, as well.

9. I have this program and was wondering how to make it accept floating numbers instead of int

This is my first problem. can you have an array for floats?

Code:
```#include <stdio.h>

float ES26[11];
int i, j, k, x=1, mean, median, mode;
float *ptr, sum;

int main ()
{
int choice;
printf("Input at most 10 floating point numbers, each entry followed by ENTER. \nInput 0 if you want to stop:\n");
for (i=1, j=1; j==1 || i==10; i++)
{
printf("%d) ", i);
scanf("%i", &ES26[i]);
if (ES26[i]==0)
{
x=i-1;
j=2;
}
if (i==10)
{
x=i;
j=2;
}
}
}```

10. You are reading as an integer here:
Code:
`scanf("%i", &ES26[i]);`