Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phkarl
/
IAX0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
779a6dcd
authored
Oct 01, 2018
by
phkarl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
03869229
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
ClassworkLab4.c
ClassworkLab4.c
0 → 100644
View file @
779a6dcd
#include <stdio.h>
#include <stdlib.h>
/* this library contains the rand() function */
#include <string.h>
int
main
(){
//Nested loops
for
(
int
i
=
0
;
i
<
3
;
i
++
){
printf
(
"%d
\n
"
,
i
);
//perform the following FOR EACH loop
for
(
int
j
=
0
;
j
<
9
;
j
++
){
//perform the following FOR EACH loop
printf
(
">>%d
\n
"
,
j
);
}
}
printf
(
"
\n
"
);
//2D arrays
int
array
[
3
][
5
]
=
{
//this is a way to fill an array at creation
{
4
,
2
,
4
,
2
,
-
1
},
//this fills a single row
{
-
3
,
55
,
1
,
223
,
2
},
//notice a comma between each row
{
2
,
4
,
5
,
2
,
1
}
//and notice that this block is indented: STYLE
};
//and a closing curly-brace to match the opöening brace at line 5
/* this nested loop pair reads the matrix */
for
(
int
i
=
0
;
i
<
3
;
i
++
){
/*i tracks with row we're on */
for
(
int
j
=
0
;
j
<
5
;
j
++
){
/* j tracks wich column we're on */
printf
(
"%d, "
,
array
[
i
][
j
]);
}
printf
(
"
\n
"
);
/* i increments to the next row onlz after we have read ALL colums */
}
printf
(
"
\n
"
);
//2D arrays with random function
for
(
int
i
=
0
;
i
<
3
;
i
++
){
for
(
int
j
=
0
;
j
<
5
;
j
++
){
array
[
i
][
j
]
=
rand
()
%
500
;
}
}
for
(
int
i
=
0
;
i
<
3
;
i
++
){
for
(
int
j
=
0
;
j
<
5
;
j
++
){
/* this generates a random number 0-499 */
printf
(
"%d, "
,
array
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
// string
char
array2
[
40
]
=
"this is a string"
;
//int breakPoint;
printf
(
"|"
);
for
(
int
i
=
0
;
i
<
40
;
i
++
){
printf
(
"%c"
,
array2
[
i
]);
}
printf
(
"|
\n
|"
);
printf
(
"%s"
,
array2
);
printf
(
"|"
);
printf
(
"
\n\n
"
);
// string with string.h library
char
string1
[
40
]
=
"this is a string"
;
char
string2
[]
=
"so is this"
;
int
length
=
strlen
(
string1
);
printf
(
"%d"
,
length
);
printf
(
"
\n
"
);
strcat
(
string1
,
" "
);
strcat
(
string1
,
string2
);
printf
(
"%s"
,
string1
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment