GarikK

Факториал и степень указателями

Mar 27th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. // Factorial.cpp : 1)Factorial N! = N * (N-1)!
  2. //                  2)Pow Operation
  3. //
  4.  
  5. #include <iostream>
  6. #include <math.h>
  7. using namespace std;
  8.  
  9. int Fact(int *ptra)
  10. {
  11.     if (*ptra == 0)
  12.     {
  13.         return 0;
  14.     }
  15.     if (*ptra == 1)
  16.     {
  17.         return 1;
  18.     }
  19.     int x = *ptra - 1;
  20.     return *ptra * Fact(&x);
  21. }
  22.  
  23. double powOperation(double *ptrb, double c)
  24. {
  25.     *ptrb = pow(*ptrb, c);
  26.     return *ptrb;
  27. }
  28.  
  29. int main()
  30. {
  31.     //Factorial operation
  32.         int a = 5;
  33.        cout << Fact(&a) << endl;
  34.  
  35.        //powOperation
  36.       double b = 3;
  37.       powOperation(&b,5);
  38.       cout << b;
  39. }
Add Comment
Please, Sign In to add comment