Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <climits>
- #include <stdlib.h>
- #include <ctime>
- #include<algorithm>
- #include <cstring>
- #include <fstream>
- using namespace std;
- void losowanie_liczb(int il,int tab[])
- {
- int a,b;
- srand(time(NULL));
- cout<<"podaj zakres"<<endl;
- cin>>a>>b;
- for(int i=0;i<il;i++)
- {
- tab[i]=rand()%(b-a+1)+a;
- cout<<tab[i]<<" ";
- }
- cout<<endl;
- }
- void losowanie_liter(int ile)
- {
- srand(time(NULL));
- string litery;
- for(int i=0;i<ile;i++){
- litery[i]=rand()%26+97;
- cout<<" "<<litery[i];}
- for(int j=0;j<ile;j++){
- for(int k=0;k<ile-1;k++){
- if(litery[k]<litery[k+1])
- swap(litery[k],litery[k+1]);
- }
- }
- cout<<endl;
- for(int d=0;d<ile;d++){
- cout<<" "<<litery[d];}
- }
- void sortowanie(int il,int tab[]){
- int g;
- cout<<"sortowanie szybkie:1 dlugie 2: "<<endl;
- cin>>g;
- if(g==2){
- for( int i=0;i<il;i++ )
- {
- for( int j=0;j<il-1;j++)
- {
- if(tab[j]>tab[j+1])
- swap(tab[j],tab[j+1]);
- }
- }
- for(int i=0;i<il;i++)
- {
- cout<<tab[i]<<" ";
- }}else
- sort(tab,tab+il);
- for(int i=0;i<il;i++)cout<<tab[i]<<" ";
- }
- void Slowo(){
- string slowo;
- cout<<"wpisz slowo"<<endl;
- cin>>slowo;
- transform(slowo.begin(),slowo.end(),slowo.begin(), ::toupper);
- cout<<slowo;
- }
- int silnia(int liczba){
- if (liczba<2) return liczba;
- return liczba*silnia(liczba-1);
- }
- int potega(int p,int w)
- {
- if(w==0) return 1;
- else
- return p*potega(p,w-1);
- }
- void palindrom()
- {
- string slowo;
- cout<<"podaj slowo"<<endl;
- cin>>slowo;
- int a=0;
- for(int i=0;i<=(slowo.length()-1)/5;i++){
- for(int j=slowo.length()-1;j>=(slowo.length()-1)/5;j--){
- if(slowo[i]!=slowo[j])
- {break;}
- else{a=1;}
- }
- if(a==1)cout<<"jest palindromem"<<endl;
- else cout<<"nie jest palindromem"<<endl;
- }}
- int main()
- {
- string litery;
- int ilosc;
- int tab[100];
- int n;
- while(n!=0)
- {
- cout<<"OPCJE:\n1.losowanie cyfr\n2. sortowanie\n3. sortowanie liter\n4.zmiana znaku zlowa\n5.silnia rekurencja\n6.potegowanie rekurencja\n7.palindrom"<<endl;
- cin>>n;
- switch(n)
- {
- case 0:
- break;
- case 1: //losowanie
- cout<<"podaj ilosc"<<endl;
- cin>>ilosc;
- losowanie_liczb(ilosc,tab);
- break;
- case 2: //sorwanie
- cout<<"podaj ilosc"<<endl;
- cin>>ilosc;
- losowanie_liczb(ilosc,tab);
- sortowanie(ilosc,tab);
- break;
- case 3: //losowanie liter i sortowanie
- cout<<"podaj ilosc"<<endl;
- cin>>ilosc;
- losowanie_liter(ilosc);
- break;
- case 4: //zmiana na duze litery
- Slowo();
- break;
- case 5: //silnia
- int s;
- cout << "podaj liczbe" << endl;
- cin >> s;
- cout << silnia(s) << endl;
- break;
- case 6: //potega
- int p,w;
- cout << "podaj podstawe i wykladnik" << endl;
- cin >> p>>w;
- cout << potega(p,w) << endl;
- break;
- case 7:
- palindrom();
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment