tags:

views:

61

answers:

1

is it possible to calculate a ratio using a function in C?? or do i have to do up a formula??

+2  A: 
float ratio (float a, float b){
  return a/b;
}

You might be having a problem with the following:

int a=5;
int b=4;
float ratio=b/a; // yields 1.0000 since it is interpreted as integer division
float ratioCorrect=(float)b/a; // yields 1.25 because yuo told the compiler to interpret numbers as floats
phimuemue
thanks for answering the poor guy's question.
Kaustubh P