Skip to content

Commit 6103472

Browse files
committed
C_Tuts_11 & 12
Using scanf. Yeah Using math in statements. Floats. Yeah.
1 parent 2fc8c7a commit 6103472

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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+
}

0 commit comments

Comments
 (0)