0

I am new to coding in C, and I was wondering if it is possible to print a float, ex: float l = 2.718281; such that the program prints: 2 2.7 2.71 2.718 2.7182 2.71828 2.718281

I know how to do this using simple printf statements, but how would I go about doing this in a for loop? This is the code I have, where I am trying to replace the number of decimal places with i, then print the statement, but it is not working

int main()
{
    float l = 2.718281;
    int i;
    for (i = 0; i < 8; i++)
    {
        printf("%.if\n", l);
    }
    return 0;
}
Dominique
  • 16,450
  • 15
  • 56
  • 112
Liku45
  • 1
  • 1

0 Answers0