I want to design a function to print the first X(where X is an integer) digits after the decimal(from 0 to X) for a floating point number Y. For eg.
print_num(12.123456,4)
should give:
12.0000000
12.1000000
12.1200000
12.1230000
12.1234000
Here is a program that I tried to write:
#include<stdio.h>
void printplaces(float N,int X)
{
for(int i =0;i<=X;i++)
{
printf("%.%df\n",N,i);
}
}
void main()
{
printplaces(23.23423342,5);
}
But it just prints the output as it is:
%df
%df
%df
%df
%df
%df
I want to know how I can use %d as an integer with %f on the same line.