Added book examples
This commit is contained in:
15
C5/displaying_variables.c
Normal file
15
C5/displaying_variables.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Declare some variables
|
||||
int a = 1, b = 2;
|
||||
float f = 1.23f;
|
||||
|
||||
// Use printf display text on the screen
|
||||
printf ("The variables are\na = %d\nb=%d\nf=%f", a, b, f);
|
||||
|
||||
// Exit from main
|
||||
return 0;
|
||||
}
|
24
C5/formatting_numbers.c
Normal file
24
C5/formatting_numbers.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#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;
|
||||
}
|
17
C5/not_displaying.c
Normal file
17
C5/not_displaying.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
// Declare some variables
|
||||
int a = 1, b = 2;
|
||||
float f = 1.23f;
|
||||
|
||||
// Use printf display text on the screen
|
||||
printf ("The variables are a, b and f");
|
||||
|
||||
// Exit from main
|
||||
return 0;
|
||||
|
||||
}
|
12
C5/printf_example_1.c
Normal file
12
C5/printf_example_1.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
printf ("This is my first computer program");
|
||||
printf ("Hello World");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
12
C5/printf_example_2.c
Normal file
12
C5/printf_example_2.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
printf ("This is my first computer program\n");
|
||||
printf ("Hello World\n");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Reference in New Issue
Block a user