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!

Printable View

- 09-29-2010BebiHelp 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! - 09-29-2010laserlight
Why do you need to convert them to int? Shouldn't your implementation of quicksort handle these numbers as float or double?

- 09-29-2010Adak
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.

- 09-29-2010Bebi
cause the program i made was using int and i have problems in converting it where floats are involved

- 09-29-2010laserlightQuote:

Originally Posted by**Bebi**

- 09-29-2010Bebi
laserlight is the solution proposed by adak acceptable? just looking for a 2nd opinion. thanks a lot

- 09-29-2010laserlightQuote:

Originally Posted by**Bebi**

- 09-29-2010Adak
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. - 09-29-2010Bebi
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;

}

}

}

- 09-29-2010laserlight
You are reading as an integer here:

Code:`scanf("%i", &ES26[i]);`