1
0

varwid.c 481 B

123456789101112131415161718
  1. /* varwid.c -- uses variable-width output field */
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. unsigned width, precision;
  6. int number = 256;
  7. double weight = 242.5;
  8. printf("Enter a field width:\n");
  9. scanf("%d", &width);
  10. printf("The number is :%*d:\n", width, number);
  11. printf("Now enter a width and a precision:\n");
  12. scanf("%d %d", &width, &precision);
  13. printf("Weight = %*.*f\n", width, precision, weight);
  14. printf("Done!\n");
  15. return 0;
  16. }