Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Zadanie 1*/
- #include <iostream>
- using namespace std;
- int SUMA(int x, int y)
- {
- int wynik = 0;
- wynik = x + y;
- return wynik;
- }
- int main()
- {
- cout << SUMA(5, 6) << endl;
- cout << SUMA(54, 67) << endl;
- cout << SUMA(55, 60) << endl;
- }
- /* Zadanie 2 */
- #include <iostream>
- using namespace std;
- int WARTOSC_BEZWZGLEDNA(int x)
- {
- if (x < 0)
- {
- x = x * -1;
- }
- return x;
- }
- int main()
- {
- cout << WARTOSC_BEZWZGLEDNA(-5)<<endl;
- cout << WARTOSC_BEZWZGLEDNA(10)<<endl;
- cout << WARTOSC_BEZWZGLEDNA(-99)<<endl;
- }
- /* Zadanie 3 */
- #include <iostream>
- using namespace std;
- bool CZY_PARZYSTA(int x)
- {
- if (x % 2 == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- int main()
- {
- cout << CZY_PARZYSTA(-5)<<endl;
- cout << CZY_PARZYSTA(10)<<endl;
- cout << CZY_PARZYSTA(-99)<<endl;
- }
- /* Zadanie 4 */
- #include <iostream>
- using namespace std;
- void SZLACZEK(int x, char y)
- {
- for (int i = 0; i < x; i++)
- {
- cout << y;
- }
- cout << "\n";
- }
- int main()
- {
- SZLACZEK(5, '*');
- SZLACZEK(10, '$');
- SZLACZEK(3, '^');
- }
- /* Zadanie 5 */
- #include <iostream>
- using namespace std;
- int POTEGA(int x, int y)
- {
- int wynik=1;
- if (y == 0)
- {
- return 1;
- }
- else
- {
- for (int i = 0; i < y; i++)
- {
- wynik = wynik * x;
- }
- return wynik;
- }
- }
- int main()
- {
- cout << POTEGA(5, 4) << endl;
- cout << POTEGA(10, 2) << endl;
- cout << POTEGA(3, 1) << endl;
- }
- /* Zadanie 6 */
- #include <iostream>
- using namespace std;
- int OBWOD_TROJKATA(int x, int y, int z)
- {
- int wynik = 0;
- if ((x + y > z) && (x + z > y) && (z + y > x))
- {
- wynik = x + y + z;
- return wynik;
- }
- else
- {
- return -1;
- }
- }
- int main()
- {
- if (OBWOD_TROJKATA(5, 3, 7) > 0)
- {
- cout << OBWOD_TROJKATA(5, 3, 7) << endl;
- }
- else cout << "Nie mozna zbudowac takiego trojkata" << endl;
- if (OBWOD_TROJKATA(10, 2, 2) > 0)
- {
- cout << OBWOD_TROJKATA(10, 2, 2) << endl;
- }
- else cout << "Nie mozna zbudowac takiego trojkata" << endl;
- if (OBWOD_TROJKATA(3, 1, 3) > 0)
- {
- cout << OBWOD_TROJKATA(3, 1, 3) << endl;
- }
- else cout << "Nie mozna zbudowac takiego trojkata" << endl;
- }
- /* Zadanie 7 */
- #include <iostream>
- using namespace std;
- int SILNIA(int x)
- {
- if (x < 2)
- {
- return 1;
- }
- return x * SILNIA(x - 1);
- }
- int main()
- {
- cout << SILNIA(5) << endl;
- cout << SILNIA(2) << endl;
- cout << SILNIA(9) << endl;
- }
- /* Zadanie 8 */
- #include <iostream>
- using namespace std;
- int MAX (int x, int y, int z)
- {
- if (x > y && x > z)
- {
- return x;
- }
- else if (y > x && y > z)
- {
- return y;
- }
- else return z;
- }
- int main()
- {
- cout << MAX(4, 3, 2) << endl;
- cout << MAX(5, 8, 1) << endl;
- cout << MAX(1, 7, 10) << endl;
- }
- /* Zadanie 9 */
- #include <iostream>
- using namespace std;
- void DZIELNIKI (int x)
- {
- for (int i = 1; i <= x; i++)
- {
- if (x % i == 0)
- {
- cout << i << " ";
- }
- }
- cout << "\n";
- }
- int main()
- {
- DZIELNIKI(5);
- DZIELNIKI(9);
- DZIELNIKI(13);
- }
- /* Zadanie 10 */
- #include <iostream>
- using namespace std;
- double ILORAZ(double x, double y)
- {
- double wynik=0;
- if (x >= 0 && y >= 0)
- {
- if (y != 0)
- {
- wynik = x / y;
- return wynik;
- }
- else return -1;
- }
- else return -2;
- }
- int main()
- {
- if (ILORAZ(4, 0) == -2)
- {
- cout << "Nie obsluguje ujemnych" << endl;
- }
- else if (ILORAZ(4, 0) == -1)
- {
- cout << "Nie dziel przez 0" << endl;
- }
- else cout << "wynik z dzielenia wynosi: " << ILORAZ(4, 2) << endl;
- if (ILORAZ(5, 3) == -2)
- {
- cout << "Nie obsluguje ujemnych" << endl;
- }
- else if (ILORAZ(5, 3) == -1)
- {
- cout << "Nie dziel przez 0" << endl;
- }
- else cout << "wynik z dzielenia wynosi: " << ILORAZ(5, 3) << endl;
- if (ILORAZ(4, -8) == -2)
- {
- cout << "Nie obsluguje ujemnych" << endl;
- }
- else if (ILORAZ(4, -8) == -1)
- {
- cout << "Nie dziel przez 0" << endl;
- }
- else cout << "wynik z dzielenia wynosi: " << ILORAZ(4, -8) << endl;
- }
- /* Zadanie 11 */
- #include <iostream>
- using namespace std;
- void PODZIELNOSC(int x, int y)
- {
- int i=1;
- int tymczasowa;
- if (x > 1)
- {
- for (int j = 0; j < x-1; j++)
- {
- i *= 10;
- }
- }
- tymczasowa = i * 10;
- do
- {
- if (i % y == 0)
- {
- cout << i << " ";
- }
- i++;
- } while (i < tymczasowa);
- cout << "\n";
- }
- int main()
- {
- PODZIELNOSC(1, 4);
- PODZIELNOSC(2, 6);
- PODZIELNOSC(3, 8);
- PODZIELNOSC(4, 92);
- }
- /* Zadanie 12 */
- #include <iostream>
- using namespace std;
- int LICZBA_CYFR(long long x)
- {
- int y = 0;
- do
- {
- x = x / 10;
- y++;
- } while (x != 0);
- return y;
- }
- int main()
- {
- cout << LICZBA_CYFR(1562156) << endl;
- cout << LICZBA_CYFR(1562156455545) << endl;
- cout << LICZBA_CYFR(1562156564561216544) << endl;
- cout << LICZBA_CYFR(15621564654656464) << endl;
- }
- /* Zadanie 13 */
- #include <iostream>
- using namespace std;
- int SUMA_CYFR(int &x)
- {
- int suma = 0;
- int y=0;
- do
- {
- y = x % 10;
- suma +=y;
- x = x / 10;
- } while (x > 0);
- x = suma;
- return x;
- }
- int main()
- {
- int x;
- cout << "Podaj liczbe: " << endl;
- cin >> x;
- do {
- SUMA_CYFR(x);
- } while (SUMA_CYFR(x) > 10);
- cout << SUMA_CYFR(x);
- }
- /* Zadanie 14 i 15 */
- #include <iostream>
- #include <math.h>
- using namespace std;
- int POLE_TROJKATA(int x, int h)
- {
- int wynik = 0;
- wynik = (x * h)/2;
- return wynik;
- }
- int POLE_TROJKATA(int x1, int y1, int x2, int y2, int x3, int y3)
- {
- int P;
- P = (abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)))/2;
- return P;
- }
- int main()
- {
- cout << POLE_TROJKATA(6, 2) << endl;
- cout << POLE_TROJKATA(2, 1, -5, 4, -1, -2) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement