Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.out
|
6
README.md
Normal file
6
README.md
Normal 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
13
average.c
Normal 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
18
interest1.c
Normal 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
19
interest2.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user