Math and Format Flashcards

(7 cards)

1
Q

What is the purpose of the printf command in Linux?

A

It formats and controls the presentation of text and numbers in output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the %s specifier do in printf?

A

It acts as a placeholder for string values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does \n do in printf?

A

It creates a new line in the output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Example: What does the command ‘printf “User: %s\nHome Directory: %s\nShell: %s\n” “$USER” “$HOME” “$SHELL”’ do?

A

It displays user information in a structured format using variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the bc command used for?

A

It performs precise arithmetic operations, including floating‑point calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ‘scale=2’ do in bc?

A

It sets the output precision to two decimal places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Example: What does ‘echo “scale=2; (2.45 + 3.67 + 4.89) / 3” | bc’ calculate?

A

The average of the three numbers with two decimal precision (3.67).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly