Code:
float a=15, b=6,x;
x=a/b;
printf("%f %", x);
I want to print 2.500 %(percent) on the screen as output. How can i print x to only 3 decimal places (3f??) and how can i also print a % sign after x?
Try this: printf("%0.3f %%", x);
if you can use C++ you can use this: cout << fixed << setprecision(3) << x << '%';