Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- void liczby(int h) // Budowanie trojkata z liczb
- {
- int t = 2;
- int m = 1;
- for (int i = 0; i < h; i++)
- {
- for (int k = 1; k < i + 2; k++)
- {
- cout << t * k*m << " ";
- }
- cout << endl;
- m++;
- }
- }
- int silnia(int n) // Silnia
- {
- int w = 1;
- for (int i = 1; i <= n; i++)
- {
- w *=i;
- }
- return w;
- }
- bool czyPalindrom(string dane) //Sprawdza czy słowo lub wyraz jest palindromem
- {
- string odwrocony;
- int dlugosc = dane.length()-1;
- for (int i = 0; i <= dlugosc; i++)
- {
- odwrocony += dane[dlugosc-i];
- }
- return odwrocony == dane;
- }
- int main()
- {
- liczby(5); cout << endl;
- cout << silnia(5) << endl;
- string wyraz;
- cout << "Podaj slowo: ";
- cin >> wyraz;
- cout << (czyPalindrom(wyraz) ? "Tak" : "Nie") << endl;
- int liczba;
- cout << "Podaj liczbe: ";
- cin >> liczba;
- cout << (czyPalindrom(to_string(liczba)) ? "Tak" : "Nie") << endl; // to_string() zmienia int na string
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement