Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
tranvu
/
iax583
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
7fa2994f
authored
Sep 17, 2018
by
tranvu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding lab 3 work
parent
5f78b4ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
Lab 3/lab work.c
Lab 3/lab work.c
0 → 100644
View file @
7fa2994f
#include <stdio.h>
#include <stdlib.h>
void
task1
();
void
task2
();
void
task3
();
int
main
()
{
printf
(
"Please input the task you want to check:
\n
1: Task 1
\n
2: Task 2
\n
3: Task 3
\n
"
);
int
input
=
0
;
scanf
(
"%d"
,
&
input
);
switch
(
input
)
{
case
1
:
task1
();
break
;
case
2
:
task2
();
break
;
case
3
:
task3
();
break
;
default:
printf
(
"Wtf did you just input?!?!?"
);
}
return
(
EXIT_SUCCESS
);
}
void
printInt
(
int
a
[],
int
size
)
{
printf
(
"All even numbers:
\n
"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
if
(
a
[
i
]
%
2
==
0
)
{
printf
(
"%d
\n
"
,
a
[
i
]);
}
}
printf
(
"All odd numbers:
\n
"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
if
(
a
[
i
]
%
2
)
{
printf
(
"%d
\n
"
,
a
[
i
]);
}
}
printf
(
"Reverse crap:
\n
"
);
for
(
int
i
=
size
-
1
;
i
>=
0
;
i
--
)
{
printf
(
"%d
\n
"
,
a
[
i
]);
}
}
void
task1
()
{
int
size
=
10
;
int
a
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
printInt
(
a
,
size
);
}
void
task2
()
{
int
length
;
printf
(
"Please input the length of the array: "
);
scanf
(
"%d"
,
&
length
);
int
a
[
length
];
int
x
=
0
;
int
y
=
1
;
int
z
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
if
(
i
<
2
)
a
[
i
]
=
i
;
else
{
z
=
x
+
y
;
x
=
y
;
y
=
z
;
a
[
i
]
=
z
;
}
}
printf
(
"Printing %d Fibonacci numbers:
\n
"
,
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
printf
(
"%d
\n
"
,
a
[
i
]);
}
printInt
(
a
,
length
);
}
void
task3
()
{
int
length
;
printf
(
"Please input array length: "
);
scanf
(
"%d"
,
&
length
);
printf
(
"Please input %d numbers:
\n
"
,
length
);
int
a
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
scanf
(
"%d"
,
&
a
[
i
]);
}
int
prev
=
a
[
0
];
int
isTrue
=
1
;
// Ascending check
for
(
int
i
=
1
;
i
<
length
;
i
++
)
{
if
(
prev
>=
a
[
i
])
{
isTrue
=
0
;
}
}
if
(
isTrue
)
{
printf
(
"Integers is ascending!"
);
return
;
}
// Descending check
prev
=
a
[
0
];
isTrue
=
1
;
for
(
int
i
=
1
;
i
<
length
;
i
++
)
{
if
(
prev
<=
a
[
i
])
isTrue
=
0
;
}
if
(
isTrue
)
{
printf
(
"Integers is descending!"
);
return
;
}
// No match
printf
(
"It is neither ascending or descending!"
);
}
\ No newline at end of file
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