Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alxm2023
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alxm2023
Commits
12739a5a
Commit
12739a5a
authored
Dec 07, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Funkcja kwadrat i ujemna
parent
ad0497c9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
funkcje2.cpp
20231207/funkcje2.cpp
+41
-0
No files found.
20231207/funkcje2.cpp
0 → 100644
View file @
12739a5a
#include <iostream>
using
namespace
std
;
// Gdy przed nazwą funkcji napiszemy cos innego niż void,
// to funkcja powinna zawierać instrukcję return i za jej pomocą "zwrócić" wynik podanego typu.
// return zwraca podany wynik i funkcja się kończy
int
kwadrat
(
int
x
)
{
return
x
*
x
;
}
// Przykład funckji, która w wyniku zwraca napis.
// Pokazuje też, że w treści funkcji może być kilka returnów.
string
ujemna_czy_dodatnia
(
int
liczba
)
{
if
(
liczba
<
0
)
{
return
"ujemna"
;
// gdy funkcja dojdzie do tego returna, to zwraca taki wynik i się kończy
}
if
(
liczba
>
0
)
{
return
"dodatnia"
;
}
return
"równa zero"
;
}
int
main
()
{
int
wynik
;
// Typowe użycie:
wynik
=
kwadrat
(
5
);
cout
<<
"Wynikiem 5^2 jest: "
<<
wynik
<<
endl
;
// Można też od razu wypisać:
cout
<<
"Natomiast 7^2 = "
<<
kwadrat
(
7
)
<<
endl
;
// Jednak samo wywołanie funkcji nie wypisuje jej wyniku
kwadrat
(
8
);
cout
<<
"Liczba 12 jest "
<<
ujemna_czy_dodatnia
(
12
)
<<
endl
;
cout
<<
"Liczba -6 jest "
<<
ujemna_czy_dodatnia
(
-
6
)
<<
endl
;
cout
<<
"Ostatnia liczba jest "
<<
ujemna_czy_dodatnia
(
6
*
2
-
12
)
<<
endl
;
return
0
;
}
\ 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