Advertisement
Dido09

C - Recursion

Nov 7th, 2022
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. /*
  6. int fact(int n)
  7. {
  8.   if (n <= 1)
  9.       return 1;
  10.   else
  11.       return n*fact(n-1);
  12. }
  13.  
  14. int _tmain(int argc, _TCHAR* argv[])
  15. {
  16.  
  17.     int n;
  18.     printf("n=");
  19.     scanf("%d", &n);
  20.     printf("n! = %d", fact(n));
  21.  
  22. }
  23. */
  24.  
  25. //задача 24
  26.  
  27. /*
  28. int find(int decimalNum)
  29. {
  30.     if (decimalNum == 0)
  31.         return 0;
  32.     else
  33.         return (decimalNum % 2 + 10 * find(decimalNum / 2));
  34. }
  35.  
  36. int main()
  37. {
  38.     int decimalNum = 10;
  39.     printf("%d\n", find(decimalNum));
  40.     return 0;
  41. }
  42. */
  43.  
  44. //varıant 2
  45.  
  46. void toBin(int decimal){
  47.     if(decimal <= 0){
  48.         return;
  49.     }
  50.     if(decimal > 0){
  51.         toBin(decimal/2);
  52.         printf("%d\n", decimal % 2);
  53.     }
  54. }
  55.  
  56. int _tmain(int argc, _TCHAR* argv[]){
  57.     toBin(10);
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement