Aligned Table
Completed
Print a table of three items. Each name is left-aligned in 8 characters (%-8s) and each quantity right-aligned in 4 (%4d): apple 12, kiwi 7, banana 130.
Input
None.
Output
Three lines.
Example
Output
apple 12 kiwi 7 banana 130
Editor
C
Hints
A minus sign left-aligns, a plain width right-aligns.
Solution explanation
Fixed widths make columns line up regardless of value length.
Show solution
#include <stdio.h>
int main() {
printf("%-8s%4d\n", "apple", 12);
printf("%-8s%4d\n", "kiwi", 7);
printf("%-8s%4d\n", "banana", 130);
return 0;
}