Advertisement
Petro_zzz

311_1902

Feb 19th, 2024
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4.  
  5. void prefix_vs_postfix() {
  6.    
  7.     int k = 5;
  8.     std::cout << k << "\n";
  9.     k++;
  10.     std::cout << k << "\n";
  11.     ++k;
  12.     std::cout << k << "\n";
  13.     double y = 1.5;
  14.     y++;
  15.     std::cout << y << "\n";
  16.  
  17.     // ++k - сначала k увеличится на 1, а затем присвоится в n
  18.     int n = ++k;
  19.     std::cout << "k:" << k << " n:" << n << "\n";
  20.     k = 7;
  21.     // ++k - сначала k присвоится в m, а затем увеличится на 1
  22.     int m = k++;
  23.     std::cout << "k:" << k << " m:" << m << "\n";
  24.  
  25.     k = 7;
  26.     std::cout << "k++: " << k++ << "\n";
  27.     std::cout << "k: " << k << "\n";
  28.  
  29.     k = 7;
  30.     std::cout << "++k: " << ++k << "\n";
  31.     std::cout << "k: " << k << "\n";
  32.  
  33.     int a = 5;
  34.  
  35.     std::cout << "a: " << a << "\n";
  36.     std::cout << "a++ + (-a * ++a): " << a++ + (-a * ++a) << "\n";
  37.     std::cout << "a: " << a << "\n";
  38.    
  39.     a = 5;
  40.     std::cout << "a: " << a << "\n";
  41.     std::cout << "++a + (-a * ++a): " << ++a + (-a * ++a) << "\n";
  42.     std::cout << "a: " << a << "\n";
  43. }
  44.  
  45. int counter = 0;
  46.  
  47. long long factorial0(int n) {
  48.  
  49.     std::cout << "Start factorial " << counter << "\n";
  50.     long long result = n;
  51.     while (n > 2) {
  52.         n--;
  53.         result *= n;
  54.     }
  55.     counter++;
  56.     return result;
  57. }
  58.  
  59.  
  60. long long factorial1(int n) {
  61.  
  62.     std::cout << "Start factorial " << counter << "\n";
  63.     long long result = n;
  64.     while (n > 2)      
  65.         result *= --n;     
  66.    
  67.     counter++;
  68.     return result;
  69. }
  70.  
  71.  
  72. void multy_tab() {
  73.  
  74.     int k = 0, n = 0;
  75.     while (n <= 9) {
  76.         k = 0;
  77.         while (k <= 9) {
  78.             std::cout << std::setw(2) << n * k++ << " ";
  79.         }
  80.         std::cout << "\n";
  81.         n++;
  82.     }
  83.  
  84. }
  85.  
  86.  
  87. int main() {
  88.     //prefix_vs_postfix();
  89.     //std::cout << !5 << std::endl;
  90.     /*std::cout << "2! = " << factorial0(2) << std::endl;
  91.     std::cout << "5! = " << factorial1(5) << std::endl;
  92.     std::cout << "4! = " << factorial0(4) << std::endl;
  93.     std::cout << "3! = " << factorial0(3) << std::endl;
  94.     std::cout << "6! = " << factorial1(6) << std::endl;
  95.     */
  96.     multy_tab();
  97.  
  98.  
  99.      
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement