I'm trying to output my results to the decimal accuracy the user has input. In other words, if they enter 145, then it outputs to 0 d.p. - if they enter 145.67, it outputs the result to 2 d.p.
I've tried achieving this by trying different things with %.lf
but didn't manage to do it so far. Is there a way to do this in C? If so, is there a name for it - so I can learn more about it.
#include <math.h>
#include <stdio.h>
int main() {
// Using long, double or something else?
double number, fourthRoot;
printf("Enter a number: ");
scanf("%lf", &number);
fourthRoot = sqrt(sqrt(number));
printf("4th root of number %lf is %.10lf", number, fourthRoot);
return 0;
}