EGZAMIN + More Funkcje

This commit is contained in:
nyosic 2025-05-07 11:17:41 +02:00
parent 3fdc9e5237
commit affc74b1fd
5 changed files with 102 additions and 5 deletions

View file

@ -1,5 +0,0 @@
{
"files.associations": {
"iostream": "cpp"
}
}

View file

@ -0,0 +1,24 @@
/*
FUNKCJA ZAMIEN
NAPISZ FUNKCJE ZAMIEN KTORA ZAMIENIA MIEJSCAMI DWIE LICZBY CALKOWITE PRZEZ REFERENCJE
*/
#include <iostream>
using namespace std;
void zamien(int &x, int &y) {
int temp = x;
x = y;
y = temp;
}
int main() {
int x = 5, y = 10;
zamien(x, y);
cout << x << " " << y;
return 0;
}

View file

@ -0,0 +1,29 @@
/*
FUNKCJA REKURENCYJNA - TO FUNKCJA KTORA WYWOLUJE SAMA SIEBIE W SWOIM CIELE
ABY ROZWIAZAC PROBLEM PRZEZ JEGO PODZIELENIE NA MNIEJSZE PODPROBLEMY
KLUCZOWE ELEMENTY REKURENCJI
1. WARUNEK ZAKONCZENIA
2. WYWOLANIE REKURENCYJNE - FUNKCJA WYWOLUJE SAMA SIEBIE W MNIEJSZYM PROBLEMEM
ZAD. Silnia n!
*/
#include <iostream>
using namespace std;
int silnia(int n) {
if(n <= 1) { //WARUNEK ZAKONCZENIA
return 1;
} else {
return n*silnia(n-1); //WYWOLANIE REKURENCYJNE
}
}
int main() {
cout << silnia(5);
return 0;
}

View file

@ -0,0 +1,21 @@
/*
NAPISZ FUNKCJE POTEGA KTORA OBLICZA X DO POTEGI Y REKURENCYJNIE
*/
#include <iostream>
using namespace std;
int potega(int x, int y) {
if(y == 0) {
return 1;
} else {
return x*potega(x,(y-1));
}
}
int main() {
cout << potega(3, 3);
return 0;
}

28
EGZAMIN/main.cpp Normal file
View file

@ -0,0 +1,28 @@
/*
Napisz program ktory wypisze liczby od 1 do 100:
-Zamiast liczb podzielnych przez 3 wypisze riko
-Zamiast liczb podzielnych przez 5 wypisze rico
-Jesli podzielna przez 3 i 5 wypisze riko35
operujemy for if
*/
#include <iostream>
using namespace std;
int main() {
for(int i = 1; i <= 100; i++) {
if(i%3 == 0 && i%5 == 0) {
cout << "riko35" << endl;
} else if(i%3 == 0) {
cout << "riko" << endl;
} else if(i%5 == 0) {
cout << "rico" << endl;
} else {
cout << i << endl;
}
}
return 0;
}