Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c++ factorial rec
- int factorial(int n) {
- if(n==1) return 1;
- return n* factorial (n-1); }
- c++ factorial ite
- int factorial(int n) {
- int result = 1;
- for ( int i = 2; i <= n; i++ ) {
- result *= i;
- }
- return result;
- }
- c++ fibonachi rec
- int fib(int N)
- {
- if (N <= 2) return 1
- else return fib(N-1) + fib(N-2);
- }
- c++ fibonachi ite
- #include <conio.h>
- int main () {
- int a=1, b=1, c=1;
- while (b<=1000) { //тело цикла while с условием, до какого числа выводить ряд
- cout <<«c= » << c <<endl;
- c=a+b;
- a=b;
- b=c;
- }
- getch ();
- return 0;
- }
- int mul(int a, int b)
- {
- if (b == 1)
- return a;
- return a + mul(a, b - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement