Kassiow

programy

May 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <climits>
  4. #include <stdlib.h>
  5. #include <ctime>
  6. #include<algorithm>
  7. #include <cstring>
  8. #include <fstream>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. void losowanie_liczb(int il,int tab[])
  14. {
  15.  
  16.     int a,b;
  17.     srand(time(NULL));
  18.  
  19.      cout<<"podaj zakres"<<endl;
  20.         cin>>a>>b;
  21.  
  22.         for(int i=0;i<il;i++)
  23.             {
  24.             tab[i]=rand()%(b-a+1)+a;
  25.             cout<<tab[i]<<" ";
  26.             }
  27.     cout<<endl;
  28. }
  29.  
  30. void losowanie_liter(int ile)
  31. {
  32.     srand(time(NULL));
  33.     string litery;
  34.         for(int i=0;i<ile;i++){
  35.             litery[i]=rand()%26+97;
  36.             cout<<" "<<litery[i];}
  37.  
  38.     for(int j=0;j<ile;j++){
  39.         for(int k=0;k<ile-1;k++){
  40.             if(litery[k]<litery[k+1])
  41.                 swap(litery[k],litery[k+1]);
  42.         }
  43.     }
  44.     cout<<endl;
  45.     for(int d=0;d<ile;d++){
  46.         cout<<" "<<litery[d];}
  47.  
  48. }
  49.  
  50.  
  51. void sortowanie(int il,int tab[]){
  52.     int g;
  53. cout<<"sortowanie szybkie:1 dlugie 2: "<<endl;
  54. cin>>g;
  55.  if(g==2){
  56.     for( int i=0;i<il;i++ )
  57.     {
  58.         for( int j=0;j<il-1;j++)
  59.         {
  60.             if(tab[j]>tab[j+1])
  61.                  swap(tab[j],tab[j+1]);
  62.         }
  63.     }
  64.     for(int i=0;i<il;i++)
  65.         {
  66.         cout<<tab[i]<<" ";
  67.         }}else
  68.         sort(tab,tab+il);
  69.         for(int i=0;i<il;i++)cout<<tab[i]<<" ";
  70. }
  71. void Slowo(){
  72.                 string slowo;
  73.                 cout<<"wpisz slowo"<<endl;
  74.                 cin>>slowo;
  75.                 transform(slowo.begin(),slowo.end(),slowo.begin(), ::toupper);
  76.                 cout<<slowo;
  77. }
  78. int silnia(int liczba){
  79.  
  80.  
  81.     if (liczba<2) return liczba;
  82.     return liczba*silnia(liczba-1);
  83.  
  84. }
  85. int potega(int p,int w)
  86. {
  87.     if(w==0) return 1;
  88.         else
  89.     return p*potega(p,w-1);
  90. }
  91. void palindrom()
  92. {
  93.     string slowo;
  94.     cout<<"podaj slowo"<<endl;
  95.     cin>>slowo;
  96.     int a=0;
  97.  
  98.     for(int i=0;i<=(slowo.length()-1)/5;i++){
  99.             for(int j=slowo.length()-1;j>=(slowo.length()-1)/5;j--){
  100.              if(slowo[i]!=slowo[j])
  101.                 {break;}
  102.              else{a=1;}
  103.             }
  104.         if(a==1)cout<<"jest palindromem"<<endl;
  105.         else cout<<"nie jest palindromem"<<endl;
  106.  
  107.  
  108. }}
  109. int main()
  110. {
  111.     string litery;
  112.     int ilosc;
  113.     int tab[100];
  114.     int n;
  115.  
  116.  
  117.     while(n!=0)
  118.     {
  119.     cout<<"OPCJE:\n1.losowanie cyfr\n2. sortowanie\n3. sortowanie liter\n4.zmiana znaku zlowa\n5.silnia rekurencja\n6.potegowanie rekurencja\n7.palindrom"<<endl;
  120.     cin>>n;
  121.         switch(n)
  122.             {
  123.             case 0:
  124.                 break;
  125.             case 1: //losowanie
  126.                 cout<<"podaj ilosc"<<endl;
  127.                     cin>>ilosc;
  128.                 losowanie_liczb(ilosc,tab);
  129.                 break;
  130.             case 2: //sorwanie
  131.                 cout<<"podaj ilosc"<<endl;
  132.                     cin>>ilosc;
  133.                 losowanie_liczb(ilosc,tab);
  134.                 sortowanie(ilosc,tab);
  135.                 break;
  136.             case 3: //losowanie liter i sortowanie
  137.                 cout<<"podaj ilosc"<<endl;
  138.                 cin>>ilosc;
  139.                 losowanie_liter(ilosc);
  140.                 break;
  141.             case 4: //zmiana na duze litery
  142.                 Slowo();
  143.                 break;
  144.             case 5: //silnia
  145.                 int s;
  146.                 cout << "podaj liczbe" << endl;
  147.                     cin >> s;
  148.                 cout << silnia(s) << endl;
  149.                 break;
  150.             case 6: //potega
  151.                 int p,w;
  152.                 cout << "podaj podstawe i wykladnik" << endl;
  153.                     cin >> p>>w;
  154.                 cout << potega(p,w) << endl;
  155.                 break;
  156.             case 7:
  157.                 palindrom();
  158.  
  159.         }
  160.     cout<<endl;
  161.     }
  162.  
  163.     return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment