Petro_zzz

lesson13_321

Sep 4th, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. void twice() {
  8.     int a = 0, b = 0;
  9.     int a_max = 5, b_max = 4;
  10.     while (a <= a_max) {
  11.         b = 0;
  12.         while (b <= b_max) {
  13.             cout << "(" << a
  14.                 << ", " << b
  15.                 << ")" << endl;
  16.             b++;
  17.         }
  18.         a++;
  19.     }
  20. }
  21.  
  22.  
  23. void test_ternarny() {
  24.     double a = 8, b = 7;
  25. // Case 1
  26.     if (a > b)
  27.         cout << a / b << endl;
  28.     else
  29.         cout << b / a << endl;
  30. // Case 2.1
  31.     cout << ((a > b) ? a / b : b / a) << endl;
  32. // Case 2.2
  33.     (a > b) ? cout << (a / b) << endl :
  34.               cout << (b / a) << endl;
  35.  
  36. }
  37.  
  38. void test_mod() {
  39.     int a = 7;
  40.     int b = 3;
  41.  
  42.     cout << b << "*" << a / b
  43.         << " + " << a % b
  44.         << " = " << a << endl;
  45. }
  46.  
  47. void test_sqrt() {
  48.     int d = 0;
  49.     double val;
  50.     while (d <= 100) {
  51.         val = sqrt(d);
  52.         if (int(val) == val)
  53.             cout << d << " -- "
  54.             << val << endl;
  55.         d++;
  56.     }
  57.  
  58.     cout << sqrt(37) << endl;
  59. }
  60.  
  61. void test_dowhile() {
  62.     int x = 0;
  63.     do {
  64.         x += 1;
  65.         cout << x << endl;
  66.     } while (x <= 5);
  67. }
  68.  
  69.  
  70. bool is_simple(int n) {
  71.     bool is_simple = true;
  72.     int k = 2;
  73.     while (k < n) {
  74.         if (n % k == 0) return false;
  75.         k++;
  76.     }
  77.     return true;
  78. }
  79.  
  80. void simple_num2() {
  81.     int n = 1;
  82.     int summ = 0;
  83.     do {       
  84.         if (is_simple(n)) {
  85.             cout << n << " ";
  86.             summ += n;
  87.         }
  88.         n++;
  89.     } while (summ < 1000);
  90.     cout << endl;
  91.     cout << summ << endl;
  92. }
  93.  
  94. void test_clock() {
  95.     int num_bam = 0;
  96.     for (int hour = 1; hour <= 12; hour++) {
  97.         num_bam += hour;       
  98.         for (int bam = 0; bam < hour; bam++) {
  99.             system("cls");
  100.             cout <<"Load: " << bam;
  101.             Sleep(500);
  102.         }
  103.         //cout << endl;
  104.     }
  105.     cout << num_bam << endl;
  106. }
  107.  
  108. void simple_num() {
  109.     int n = 1, k = 0, summ = 0;
  110.     bool is_simple;
  111.     while (n <= 1000) {    
  112.         k = 2;
  113.         is_simple = true;
  114.         while (k < n) {
  115.             if (n % k == 0) {
  116.                 is_simple = false;
  117.                 break;
  118.             }
  119.             k++;
  120.         }
  121.         if (is_simple) {
  122.             cout << n << " ";
  123.             summ += n;
  124.         }
  125.         n++;
  126.     }
  127.     cout << endl;
  128. }
  129.  
  130.  
  131. int main() {
  132.     //twice();
  133.     //test_ternarny();
  134.     //test_dowhile();
  135.     //simple_num2();
  136.  
  137.     test_clock();
  138.  
  139.     return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment