My goal of my program is to cut off pi at a given point as dictated by the user.
I have figured out how to do it, but I cannot figure out how to get rid of the trailing zeroes.
#include <stdio.h>
#include <math.h>
int main()
{
int i,length;
double almost_pi,pi;
printf("How long do you want your pi: ");
scanf("%d", &length);
pi = M_PI;
i = pi * pow(10,length);
almost_pi = i / pow(10,length);
printf("lf\n",almost_pi);
return 0;
}
Let's say user inputs 3, it should return 3.141, but it is returning 3.141000.
Please and thanks!