Skip to content

Commit 2404a71

Browse files
committed
Merge pull request buckyroberts#48 from Nodetails/master
Tuts 11 & 12
2 parents 3c758f5 + f0a20cb commit 2404a71

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

C/10_cProgramming.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This is in a header file. Go to "File" --> New -->
2+
// Empty File, call it "Buckysroom.h"
3+
4+
// Done right, a headers folder should show up on CodeBlocks
5+
6+
# define MYNAME "Bucky"
7+
# define AGE 28
8+
9+
//////////////////////////////////////////
10+
11+
12+
// Shows how values defined in header file work.
13+
14+
#include <stdio.h>
15+
#include <stdlib.h>
16+
#include "Buckysinfo.h"
17+
18+
int main()
19+
{
20+
int girlsAge = (AGE / 2) + 7;
21+
printf("%s can date girls age %d or older.", MYNAME, girlsAge);
22+
return 0;
23+
}

C/11_cProgramming.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// using scanf stuff
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
8+
int main()
9+
{
10+
11+
char firstName[20];
12+
char crush[20];
13+
int numberOfBabies;
14+
15+
printf("What is your name? \n");
16+
scanf("%s", firstName);
17+
18+
printf("Who are you going to marry? \n");
19+
scanf("%s", crush);
20+
21+
printf("How many kids will you have? \n");
22+
scanf("%d", &numberOfBabies);
23+
24+
printf("%s and %s are in love and will have %d babies", firstName, crush, numberOfBabies);
25+
26+
return 0;
27+
}

C/12_cProgramming.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
// Math in statements, floats. Code modified a bit
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
8+
int main()
9+
{
10+
11+
int weight = 595;
12+
printf("I weigh %d lbs. \n", weight + 12);
13+
printf("I weigh %d lbs. \n", weight / 12);
14+
printf("I weigh %d lbs. \n\n", weight % 12);
15+
16+
int a = 86;
17+
int b = 21;
18+
19+
printf("%d \n", a/b);
20+
21+
float c = 86.0;
22+
float d = 21.0;
23+
printf("%f \n", c/d);
24+
25+
return 0;
26+
}

C/13_cProgramming.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
// Order of operations
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
8+
int main()
9+
{
10+
11+
int a = 4 + 2 * 6;
12+
printf("Result: %d \n", a);
13+
a = (4 + 2) * 6;
14+
printf("Result: %d \n", a);
15+
16+
return 0;
17+
}

C/14_cProgramming.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// Moar math.
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
8+
int main()
9+
{
10+
11+
float age1, age2, age3, average;
12+
age1 = age2 = 4.0;
13+
14+
printf("Enter your age\n");
15+
scanf("%f", &age3);
16+
17+
average = (age1 + age2 + age3) / 3;
18+
printf("\n The average age of the group is %f", average);
19+
20+
return 0;
21+
}

C/15_cProgramming.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
// Even moar math.
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
8+
int main()
9+
{
10+
11+
int pageViews = 0;
12+
13+
pageViews = pageViews + 1;
14+
printf("Page views: %d \n", pageViews);
15+
pageViews = pageViews + 1;
16+
printf("Page views: %d \n", pageViews);
17+
pageViews = pageViews + 1;
18+
printf("Page views: %d \n", pageViews);
19+
20+
float balance = 1000.00;
21+
22+
balance *= 1.1;
23+
printf("Balance: %f \n", balance);
24+
balance *= 1.1;
25+
printf("Balance: %f \n", balance);
26+
balance *= 1.1;
27+
printf("Balance: %f \n", balance);
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)