- 2072 Kartik · 4 marks
Output for given format specifiers
Short answer
printf("[%10i]",456); yields [ 456] (right-aligned). printf("[%3c]",'A'); yields [ A]. printf("[%-10.3f]",3.14159); yields [3.142 ] (left-aligned). printf("[%x]",255); yields [ff] (hex).
Give suitable example with sample output for the following: %10i, %3c, %-10.3f and %x.
Each specifier is shown between brackets so the spaces can be seen.
#include <stdio.h>
int main(void)
{
printf("[%10i]\n", 456);
printf("[%3c]\n", 'A');
printf("[%-10.3f]\n", 3.14159);
printf("[%x]\n", 255);
return 0;
}
Output:
[ 456]
[ A]
[3.142 ]
[ff]
| Specifier | Meaning | Result for the example |
|---|---|---|
%10i | integer in a field 10 wide, right aligned | [ 456] (7 blanks, then 456) |
%3c | character in a field 3 wide, right aligned | [ A] |
%-10.3f | float with 3 decimals, left aligned in width 10 | [3.142 ] |
%x | integer in lowercase hexadecimal | [ff] for 255 |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Correct program: do-while and pow · Computer Programming, chapter 3
- Correct program: case array and average · Computer Programming, chapter 3
- RECORD.txt item cost with VAT · Computer Programming, chapter 10
- Sample mean income of 10 retailers · Probability and Statistics, chapter 4
- Clay 10 m, 2.54 cm sample, half settlement · Soil Mechanics, chapter 9
- Theodolite traverse ABCDA, booking format with VCR · Surveying I, chapter 7
- Sample mean, variance, CV: patients' sleep hours · Probability and Statistics, chapter 1 · asked 3×