145k views
5 votes
Write calls to printf to display the variable x in the following formats:

a. x is a float. Format: Exponential notation, left justified, in field size of 5 with 3 digits after the decimal point.
b. x is an int. Format: Right justified, in a 11 digit field.

1 Answer

4 votes

Answer:

a) printf("%-5.3e",x);

b) printf("%10llu",x);

Step-by-step explanation:

We can assign any value to x at the start of program:

For Example:

float x = 72.149;

Then in order to print exponential notation, left justified, in field size of 5 with 3 digits after the decimal point, we need to use the following format:

printf("%-5.3e",x);

where e represent exponential notation.

5 represents field size of 5 and 3 represents digits after decimal point.

In order to print x as right justified, in a 11 digit field, we need to use the following format:

printf("%10llu",x);

User T D
by
4.7k points