commit a7c7dc30f7b125a93d2166eee7cde5d406e6e73d Author: Jack-Benny Persson Date: Tue Oct 13 04:39:07 2015 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f47cb20 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.out diff --git a/README.md b/README.md new file mode 100644 index 0000000..2ee5e45 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Teaching myself C # +This is just miscellaneous code I write while teaching myself C. Some of this is +from the book "Vägen till C" by Jan Skansholm & Ulf Bilting. Some is from the +classic book "The C Programming Language" by Brian Kernighan & Dennis Ritchie. +Other code is just small projects I've made to experiment and teach myself how +to code in C. diff --git a/average.c b/average.c new file mode 100644 index 0000000..605c463 --- /dev/null +++ b/average.c @@ -0,0 +1,13 @@ +#include + +int main() +{ + float nr1, nr2; + printf("First number: "); + scanf("%f", &nr1); + printf("Second number: "); + scanf("%f", &nr2); + printf("Total: %.2f\n", nr1+nr2); + printf("Average: %.2f\n", (nr1+nr2)/2); + return 0; +} diff --git a/interest1.c b/interest1.c new file mode 100644 index 0000000..04d120f --- /dev/null +++ b/interest1.c @@ -0,0 +1,18 @@ +#include +#define YEARS 10 + +int main() +{ + float cap, interest; + int year; + printf("Invested capial: "); scanf("%f", &cap); + printf("Interest? "); scanf("%f", &interest); + printf("\n Year Holding\n ==== =======\n"); + + for (year = 1; year <= YEARS; year++) + { + cap = cap * (1 + interest / 100); + printf("%5d%13.2f\n", year, cap); + } + return 0; +} diff --git a/interest2.c b/interest2.c new file mode 100644 index 0000000..800e9b1 --- /dev/null +++ b/interest2.c @@ -0,0 +1,19 @@ +#include + +int main() +{ + float cap, interest; + int year; + int nrOfYears; + printf("Invested capial: "); scanf("%f", &cap); + printf("Interest? "); scanf("%f", &interest); + printf("How many years? "); scanf("%d", &nrOfYears); + printf("\n Year Holding\n ==== =======\n"); + + for (year = 1; year <= nrOfYears; year++) + { + cap = cap * (1 + interest / 100); + printf("%5d%13.2f\n", year, cap); + } + return 0; +}