-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncstart.c
More file actions
108 lines (91 loc) · 1.14 KB
/
funcstart.c
File metadata and controls
108 lines (91 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Introduction to Functions
// 10/20/16
#include <stdio.h>
#include <string.h>
// say hi
void say_hi()
{
printf("hi\n");
printf("\n");
}
// N dashes
void dashes( int N )
{
int i;
for (i = 0; i < N; ++i)
{
printf("-");
}
printf("\n");
}
// sum 1 to N
int sumto(int N)
{
int sum = 0;
int k;
for(k = 1; k <= N; ++k)
{
sum = sum + k;
}
return sum;
}
// roll a 6-sided dice
int roll()
{
int r;
r = rand()% 6 + 1;
return r;
}
// get a random upper-case letter
char getUpper()
{
char c;
c = 'A' + rand() % 26;
return c;
}
// draw a box that is N x N @
void box(int N)
{
int r;
int c;
for(r = 0; r < N; ++r)
{
for(c = 0; c < N; ++c)
{
printf("@");
}
printf("\n");
}
}
int main()
{
int res, i;
char let;
int d;
int e;
int x;
srand(time(NULL));
say_hi();
dashes(10);
dashes(3);
dashes(30);
d = roll();
e = roll();
printf("Rolled: %d %d\n", d, e);
printf("find sum up to: ");
scanf("%d", &x);
res = sumto(x);
printf("Sum 1 to 6 is %d\n", res);
dashes(10);
for (i = 0; i < 5; ++i)
{
let = getUpper();
printf("%c ", let);
}
printf("\n");
dashes(10);
box(5);
dashes(10);
box(3);
return 0;
}