Added book examples

This commit is contained in:
Louise Brown
2022-04-08 16:12:38 +01:00
parent 5b205092a7
commit 1c0a9e7b6a
59 changed files with 1381 additions and 0 deletions

15
C5/displaying_variables.c Normal file
View 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
View 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
View 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
View 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
View 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;
}