-1
#include <stdio.h>


int main()
{
int x;
float f1[11], f2[11], s;

for (x = 1; x <= 10; x++)
{
    f1[x] = (x * x) / 4;
    printf("f1(%d)=%.2f\n", x, f1[x]);

}

return 0;
}

f1 = (x^2)/4

Current output is:

f1(1) = 0.00

f1(2) = 1.00

f1(3) = 2.00 //etc

I kinda want those decimals though.

f1(1) = 0.25

f1(2) = 1.00

f1(3) = 2.25

Paul
  • 1
  • 1

1 Answers1

1

What you do with a value doesn't affect how it's computed. So the fact that you store the result of some math in a double doesn't change the fact that you're performing integer operations.

There are lots of fixes, but the simplest is probably (1.0 * x * x) / 4.0.

Barmar
  • 741,623
  • 53
  • 500
  • 612
David Schwartz
  • 179,497
  • 17
  • 214
  • 278