Initial commit

This commit is contained in:
2015-10-13 04:39:07 +02:00
commit a7c7dc30f7
5 changed files with 57 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.out

6
README.md Normal file
View File

@@ -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.

13
average.c Normal file
View File

@@ -0,0 +1,13 @@
#include <stdio.h>
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;
}

18
interest1.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#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;
}

19
interest2.c Normal file
View File

@@ -0,0 +1,19 @@
#include <stdio.h>
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;
}