diff --git a/c_primer_plus/chapter03/01.c b/c_primer_plus/chapter03/01.c new file mode 100644 index 0000000..afc1416 --- /dev/null +++ b/c_primer_plus/chapter03/01.c @@ -0,0 +1,25 @@ +#include +#include +#include + + + +int main (void) { + + int a = INT_MAX; + float b = FLT_MAX; + + // overflow + printf("Integer overflow: %d\n", a+1); + printf("Float overflow: %f\n", b + 1.0); + + a = INT_MIN; + b = -FLT_MAX; + + // underflow + printf("Integer underflow: %d\n", a-1); + printf("Float underflow: %f\n", b-1.0); + + return 0; + +} \ No newline at end of file diff --git a/c_primer_plus/chapter03/02.c b/c_primer_plus/chapter03/02.c new file mode 100644 index 0000000..929976a --- /dev/null +++ b/c_primer_plus/chapter03/02.c @@ -0,0 +1,21 @@ +#include + + + +int main (void) { + + unsigned int a; + + printf("Give an ASCII code value: "); + scanf("%u", &a); + + if (a > 127) { + printf("Outside of ASCII range\n"); + return 1; + } else { + printf("The character is: %c\n", a); + } + + return 0; + +} \ No newline at end of file diff --git a/c_primer_plus/chapter03/03.c b/c_primer_plus/chapter03/03.c new file mode 100644 index 0000000..755f05f --- /dev/null +++ b/c_primer_plus/chapter03/03.c @@ -0,0 +1,12 @@ +#include + + + +int main (void) { + + printf("Startled by the sudden sound, Sally shouted,\n"); + printf("\"By the Great Pumpkin, what was that!\"\n"); + + return 0; + +} \ No newline at end of file diff --git a/c_primer_plus/chapter03/04.c b/c_primer_plus/chapter03/04.c new file mode 100644 index 0000000..403089a --- /dev/null +++ b/c_primer_plus/chapter03/04.c @@ -0,0 +1,17 @@ +#include + + + +int main (void) { + + float a; + + printf("Enter a floating-point value: "); + scanf("%f", &a); + printf("fixed-point notation: %f\n", a); + printf("exponential notation: %e\n", a); + printf("p notation: %a\n", a); + + return 0; + +} diff --git a/c_primer_plus/chapter03/05.c b/c_primer_plus/chapter03/05.c new file mode 100644 index 0000000..77b1d47 --- /dev/null +++ b/c_primer_plus/chapter03/05.c @@ -0,0 +1,22 @@ +#include +#include + + + +int main (void) { + + unsigned age; + + printf("Enter your age: "); + scanf("%u", &age); + + if ((unsigned int)(UINT_MAX / 3.156e7) < age) { + printf("Integer overflow\n"); + return 1; + } else { + printf("You are %u seconds old\n", (unsigned int)(age * 3.156e7)); + } + + return 0; + +} diff --git a/c_primer_plus/chapter03/06.c b/c_primer_plus/chapter03/06.c new file mode 100644 index 0000000..80ebb0b --- /dev/null +++ b/c_primer_plus/chapter03/06.c @@ -0,0 +1,15 @@ +#include + + + +int main (void) { + + float quarts; + + printf("Enter a amount of water, in quarts: "); + scanf("%f", &quarts); + printf("Number of molecules: %e\n", quarts * 950.0 / 3.0e-23); + + return 0; + +}