Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- int silnia_iter( int liczba ){
- int result = 1;
- if ( liczba > 0 ){
- for ( int i = 2; i <= liczba; i++){
- result = result * i;
- }
- }
- return result;
- }
- int silnia_rekur( int liczba ){
- int result;
- if ( liczba == 1 ){
- return 1;
- } else {
- return(silnia_rekur(liczba - 1)*liczba);
- }
- }
- void wspak( string znaki ){
- static int dlugosc = znaki.length() -1;
- cout << znaki[dlugosc];
- if (dlugosc > 0) {
- dlugosc--;
- wspak(znaki);
- }
- }
- bool palindrom( string znak ){
- int dlugosc = znak.length();
- int i = 0;
- bool check = true;
- if ( dlugosc % 2 == 1 ){
- while( i < (dlugosc-1)/2 ){
- if ( znak[i] != znak[dlugosc-i-1] ){
- check = false;
- break;
- }
- i++;
- }
- } else {
- while ( i < dlugosc/2 ){
- if(znak[i] != znak[dlugosc-i-1]){
- check = false;
- break;
- }
- i++;
- }
- }
- return check;
- }
- void menu(){
- int wybor;
- do{
- cout << "1. Sprawdz palindrom." << endl;
- cout << "2. Wyjscie" << endl;
- cin >> wybor;
- if ( wybor == 1 ){
- string wyraz;
- cout << "Podaj wyraz" << endl;
- cin >> wyraz;
- if (palindrom(wyraz)){
- cout << "To jest palindrom" << endl;
- } else {
- cout << "To nie jest palindrom" << endl;
- }
- }
- } while ( wybor == 1 );
- }
- int main(){
- menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment