Advertisement
Skygen

1. darbs Algorimti

Sep 7th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. c++ factorial rec
  2.  
  3. int factorial(int n) {
  4. if(n==1) return 1;
  5. return n* factorial (n-1); }
  6.  
  7. c++ factorial ite
  8.  
  9. int factorial(int n) {
  10. int result = 1;
  11.  
  12. for ( int i = 2; i <= n; i++ ) {
  13. result *= i;
  14. }
  15. return result;
  16. }
  17.  
  18. c++ fibonachi rec
  19.  
  20. int fib(int N)
  21. {
  22.   if (N <= 2) return 1
  23.   else return fib(N-1) + fib(N-2);
  24. }
  25. c++ fibonachi ite
  26.  #include <conio.h>
  27.  int main () {
  28.  int a=1, b=1, c=1;
  29.  while (b<=1000) {         //тело цикла while с условием, до какого числа выводить ряд
  30. cout <<«c= » << c <<endl;
  31.  c=a+b;
  32.  a=b;
  33.  b=c;
  34.  
  35. }
  36.  getch ();
  37.  return 0;
  38.  }
  39.  
  40.  
  41.  
  42. int mul(int a, int b)
  43. {
  44.     if (b == 1)
  45.         return a;
  46.     return a + mul(a, b - 1);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement