Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <conio.h>
- #include <string>
- using namespace std;
- int silnia(int x);
- float pier(int a, int b, int c);
- int fib(int y);
- char podwojenie(string tablica);
- int znak1(string napis, char znak);
- string odwroc(string doOdwrocenia);
- void main()
- {
- /*int x;
- //Silnia
- cout << "Podaj liczbe, z ktorej chcesz policzyc silnie!: \t";
- cin >> x;
- cout << "Silnia z : " << x << " wynosi: \t" << silnia(x)<<endl;
- //Rownanie kwadratowe
- int a, b, c;
- cout << "Podaj a: ";
- cin >> a;
- cout <<endl;
- cout << "Podaj b: ";
- cin >> b;
- cout << endl;
- cout << "Podaj c: ";
- cin >> c;
- cout << endl;
- cout << pier(a, b, c);
- //Ciag Fibonnaciego!
- int f;
- cout << "Podaj liczbe do ciagu Fibonacciego!: ";
- cin >> f;
- cout << endl << fib(f);
- string wyraz;
- cout << "Podaj lancuch do podwojenia! " << endl;
- cin >> wyraz;
- cout << wyraz << endl;
- cout << "Podwojony wyraz: ";
- podwojenie(wyraz);
- cout
- << endl;
- string wyraz1;
- char znak;
- cout << "Podaj lancuch " << endl;
- cin >> wyraz1;
- cout << "Podaj znak " << endl;
- cin >> znak;
- cout << "Liczba wystapien znaku: " << znak1(wyraz1, znak);
- */
- string lan;
- cout << "Podaj lan do odwrocenia: ";
- cin >> lan;
- cout << odwroc(lan);
- int sortowanie(int *tablica);
- int n;
- int *tablica;
- cout << "Podaj ile elementow chcesz wprowadzic do tablicy!: ";
- cin >> n;
- tablica = new int[n];
- sortowanie(tablica);
- delete[] tablica;
- system("pause");
- }
- int silnia(int x)
- {
- if (x > 1)
- {
- return silnia(x - 1)*x;
- }
- else if(x == 1)
- {
- return 1;
- }
- else
- {
- cout << "Brak silni z liczby ujemnej!" << endl;
- return -1;
- }
- }
- float pier(int a, int b, int c)
- {
- float delta = b*b - 4 * a*c;
- float x1, x2, x0;
- if (delta < 0)
- {
- cout << "Brak pierwiastkow!" << endl;
- }
- else if (delta == 0)
- {
- x0 = -1 * b / 2 * a;
- cout << "Funkcja posiada jeden pierwiastek! : " << x0;
- }
- else
- {
- x1 = (-1 * b - sqrt(delta) )/ 2 * a;
- x2 = (-1 * b + sqrt(delta)) / 2 * a;
- cout << "Funkcja posiada dwa pierwiastki: " << endl;
- cout << "x1 = " << x1 << endl;
- cout << "x2 = " << x2 << endl;
- }
- return 0;
- }
- int fib(int y)
- {
- if (y > 0)
- {
- if (y == 1)
- {
- return 1;
- }
- if (y == 2)
- {
- return 1;
- }
- else
- {
- return fib(y - 2)+fib(y - 1);
- }
- }
- }
- char podwojenie(string tablica)
- {
- int i = 0;
- for (i; i < tablica[i] != '\0'; i++)
- {
- cout<< tablica[i];
- cout<< tablica[i];
- }
- return 0;
- }
- int znak1(string napis, char znak)
- {
- int ile = 0;
- for (int i = 0; napis[i] != '\0';i++)
- {
- if (znak == napis[i])
- {
- ile++;
- }
- }
- return ile;
- }
- string odwroc(string doOdwrocenia)
- {
- int dlugosc = 0;
- string pomocniczy,dupa;
- for (int i = 0; (doOdwrocenia[i] != '\0'); i++)
- {
- dlugosc++;
- }
- for (int j = 0; j < dlugosc / 2; j++)
- {
- pomocniczy[j] = doOdwrocenia[dlugosc - j-1];
- }
- return pomocniczy;
- }
- int sortowanie(int *tablica)
- {
- cout << "Podaj elementy do tablicy!: \n";
- for (int i = 0; i < n; i++)
- {
- cin >> *(tablica + i);
- }
- cout << "Elementy w Twojej tablicy: ";
- for (int i = 0; i < n; i++)
- {
- cout << *(tablica + i);
- cout << " ";
- }
- for (int j = 1; j < n; j++)
- {
- for (int i = 1; i < n; i++)
- {
- if (*(tablica + i) > *(tablica + i - 1))
- {
- int pomocnicza;
- pomocnicza = *(tablica + i - 1);
- *(tablica + i - 1) = *(tablica + i);
- *(tablica + i) = pomocnicza;
- }
- }
- }
- cout << "Posortowana tablica: ";
- for (int i = 0; i < n; i++)
- {
- cout << *(tablica + i);
- cout << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement