Advertisement
rootuss

3.16

Nov 17th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6.  
  7. float silnia(float s)
  8. {
  9.     if (s==0)
  10.     {
  11.         return 1;
  12.     }
  13.     else
  14.         return silnia(s-1)*s;
  15. }
  16.  
  17. float suma(float su)
  18. {
  19.     return ((su+1)*su)/2;
  20. }
  21.  
  22. int main()
  23. {
  24.     srand(time(NULL));
  25.     int x = 5+ rand()%6;
  26.     cout<<"Liczba x: ";
  27.     cout<<x;
  28.     cout<<endl;
  29.  
  30.     int y;
  31.     cout << "Podaj y: " ;
  32.     cin>>y;
  33.  
  34.     while (y<=0)
  35.         {
  36.             cout<<"Podaj poprawne y!"<<endl;
  37.             cout<<"Liczba y: ";
  38.             cin>>y;
  39.         }
  40.  
  41.     cout<<endl;
  42.     cout<<endl;
  43.     cout<<"Dzialanie to: \n"<<endl;
  44.     cout<<x<<"! + "<<y<<"!"<<endl;
  45.  
  46.     for(int z=1;z<=2*y;z++)
  47.     {
  48.         cout<<"-";
  49.     }
  50.     cout<<endl;
  51.  
  52.     int n=1;
  53.     while(n<=y)
  54.     {
  55.         if (n==y)
  56.         {
  57.             cout<<n<<endl;
  58.             break;
  59.         }
  60.         cout<<n<<"+";
  61.         n++;
  62.     }
  63.  
  64.  
  65.     float wynik;
  66.     wynik=(silnia(x)+silnia(y))/suma(y);
  67.  
  68.     cout<<endl;
  69.     cout<<"\na wynik to:  \n\n"<<wynik;
  70.     cout<<endl;
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement