Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PW_zadania_4.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int num;
- do
- {
- cout << "Witamy w programie pw_zadania_4" << endl << "Podaj numer zadania a program zacznie prace " << endl << "1.Zadanie 1" << endl << "2.Zadanie 2" << endl << "3.Zadanie 3" << endl << "0.Koniec" << endl;
- cin >> num;
- cin.ignore();
- switch (num)
- {
- case 1:
- {
- char tab [30];
- cout << "Wpisz dowolny wyraz (max 30znakow), a program sprawdzi czy jest on palindromem" << endl;
- cin >> tab;
- cout << tab << endl;
- int n = strlen(tab);
- for(int a = n-1; a>0; a--) cout << tab[a] << endl;
- bool nie_jest_palindromem, wyraz_nieparzysty;
- nie_jest_palindromem = false;
- wyraz_nieparzysty = false;
- int i, L2;
- for(i=0; i < n; i++)
- {
- if(tab[i]==tab[n-1-i])cout << "";
- else nie_jest_palindromem = true;
- L2=n % 2 == 0 ? 1 : 0;
- if(L2==1)cout << "";
- else wyraz_nieparzysty = true;
- }
- if (nie_jest_palindromem == true) cout << "wyraz nie jest palindromem" << endl;
- else cout << "wyraz jest palindromem" << endl;
- if (wyraz_nieparzysty == true) cout << "wyraz nieparzysty" << endl << endl;
- else cout << "wyraz parzysty" << endl << endl;
- cin.get();
- break;
- }
- case 0:
- return 0;
- default:
- cout<<"Nieprawidlowa cyfra, wybierz cyfre z menu odpowiadajaca ktoremus z dzialan" << endl;
- }
- }while(num!=0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement