Option 4: Print out floating point a) If option 4 is selected, the user should b
ID: 3589968 • Letter: O
Question
Option 4: Print out floating point a) If option 4 is selected, the user should be prompted to enter a number: number you For input 45.678. the output must then be 45.678000 This option is indeed quite challenging because you cannot use the format indicator 9of inside the printfO. The decimal point can be printed out directly or use the %c option. but you need to find out its position and figure out ways to print out the portions before and after the decimal point. You must also have exactly 6 digits after the decimal point just like that with the %f option.Explanation / Answer
Following is the code for priting a floating number with 6 digits after decimal using %d:
#include<stdio.h>
int main(){
double a;
int b;
int c;
printf("Please enter the number you would like to print:");
scanf("%lf",&a);
b = a;
a = a - b;
a = a * 1000000;
c = 0;
while (c < a){
c++;
}
printf("%d.%d",b,c);
}