78.5k views
3 votes
Write a statement for each of the following:

a) Print 1234 right-justified in a 10 digit field.
b) Print 123.456789 in exponential notation with a sign (+ or -) and 3 digits of precision.
c) Read a double value into variable number. d) Print 100 in octal form preceded by 0.
e) Read a string into character array string.

1 Answer

4 votes

Final answer:

To print numbers in different formats and read values, you can use programming language functions like printf and cin. For example, to print 1234 right-justified in a 10-digit field, you can use printf("%10d", 1234). To read a double value into a variable named number, you can use cin >> number.

Step-by-step explanation:

a) To print 1234 right-justified in a 10-digit field, you can use the printf function in programming languages like C++. Here's an example:

printf("%10d", 1234);

b) To print 123.456789 in exponential notation with a sign and 3 digits of precision, we can use the printf function again. Here's an example:

printf("%+0.3e", 123.456789);

c) To read a double value into a variable named number, you can use the appropriate input function in your chosen programming language. Here's an example in C++:

double number;
std::cin >> number;

d) To print 100 in octal form preceded by 0, you can use the printf function once again. Here's an example:

printf("%#o", 100);

e) To read a string into a character array called string, you can use the appropriate input function. Here's an example in C++:

char string[100];
std::cin.getline(string, 100);

User Alexander Matusiak
by
6.7k points