Advertisement
ZhilinskiyG

Klassnaya rabota

Apr 16th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include <fstream>
  4. using namespace std;
  5. ofstream fout;
  6. int fib(int a){
  7.     if (a == 0)
  8.         return 0;
  9.     if (a == 1)
  10.         return 1;
  11.     return fib(a - 1) + fib(a - 2);
  12. }
  13. int fact(int n){
  14.     if (n == 0)
  15.         return 1;
  16.     return n*fact(n - 1);
  17. }
  18. char str[8];
  19. int generate(int pos, int size){
  20.     if (pos == size){
  21.         str[pos] = '\0';
  22.     fout << str << endl;
  23. }
  24. else{
  25.         for (int i = 0; i < 32; i++)
  26.         {
  27.             if (pos == 0) cout << endl << i << endl;
  28.             if (pos == 1) cout << i << ' ';
  29.             str[pos] = 'a' + i;
  30.             generate(pos + 1, size);
  31.         }
  32.     }
  33. }
  34.  
  35. int _tmain(int argc, _TCHAR* argv[])
  36. {
  37.     fout.open("pass.txt");
  38.     cout << fib(0)<<endl;
  39.     cout << fact(3) << endl;
  40.     generate(0, 4);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement