Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gürcan Güleç
/
iag0581
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cf457619
authored
Sep 24, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the styles and added a few comments
parent
901e8f6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
32 deletions
labs/lab2/dowhile.c
labs/lab2/forloop.c
labs/lab2/whilebreak.c
labs/lab2/dowhile.c
View file @
cf457619
#include <stdio.h>
#include <stdio.h>
int
main
(
)
int
main
(
void
)
{
{
int
countDown
=
11
;
// declaring a variable
do
int
countDown
=
11
;
{
// starting the loop
countDown
--
;
do
printf
(
"The value of countDown is %d
\n
"
,
countDown
);
{
}
while
(
countDown
>
0
);
countDown
--
;
return
0
;
// printing out the value of countDown
printf
(
"The value of countDown is %d
\n
"
,
countDown
);
}
while
(
countDown
>
0
);
return
0
;
}
}
labs/lab2/forloop.c
View file @
cf457619
#include <stdio.h>
#include <stdio.h>
int
main
(
)
int
main
(
void
)
{
{
int
sum
=
0
;
int
sum
=
0
;
for
(
int
number
=
0
;
number
<=
10
;
number
++
)
//Initialize for loop
// starting the loop
{
for
(
int
number
=
0
;
number
<=
10
;
number
++
)
printf
(
"The value of number is %d
\n
"
,
number
);
//Print out the value of i
{
sum
=
sum
+
number
;
// printing out the value of number
}
printf
(
"The value of number is %d
\n
"
,
number
);
printf
(
"The sum of all the numbers is %d
\n
"
,
sum
);
// adding number's value to sum
return
0
;
sum
=
sum
+
number
;
}
// printing out the value of sum
printf
(
"The sum of all the numbers is %d
\n
"
,
sum
);
return
0
;
}
}
labs/lab2/whilebreak.c
View file @
cf457619
#include <stdio.h>
#include <stdio.h>
int
main
(
)
int
main
(
void
)
{
{
int
number
=
0
;
int
number
=
0
;
while
(
number
<=
10
)
while
(
number
<=
10
)
{
{
printf
(
"A = %d
\n
"
,
number
);
printf
(
"A = %d
\n
"
,
number
);
if
(
number
==
3
)
// using if to decide which number to stop
{
if
(
number
==
3
)
printf
(
"Stopping here cuz my favorite number is %d
\n
"
,
number
);
{
break
;
// printing out the thing I wanna print out :P
}
printf
(
"Stopping here cuz my favorite number is %d
\n
"
,
number
);
// making it stop with break;
number
++
;
break
;
}
}
// increasing the value of number
return
0
;
number
++
;
}
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