This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/C5/FormattingNumbers/formatting_numbers.c

24 lines
624 B
C
Raw Normal View History

2022-04-08 15:12:38 +00:00
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// Declare some variables
int a = 123;
float f = 12.456f;
// Use printf display text on the screen
printf ("Examples of integer formatting\n");
printf ("a = %d (no modifier)\n", a);
printf ("a = %6d (w:6, justify:right)\n", a);
printf ("a = %-6d (w:6 )\n", a);
// Use printf display text on the screen
printf ("Examples of float formatting\n");
printf ("f = %f (no modifier)\n", f);
printf ("f = %6.2f (w:6, 2dp, justify:right)\n", f);
printf ("f = %-6.1f (w:6, 1dp)\n", f);
// Exit from main
return 0;
}