Advertisement
Petro_zzz

урок10_322

Aug 18th, 2023 (edited)
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void nums() {
  6.     int a = 1;
  7.     int ch1, ch2, ch3; // для суммы
  8.     int n;             // это для кол.-ва цифр
  9.  
  10.     ch1 = a % 10;
  11.     a /= 10;
  12.     ch2 = a % 10;
  13.     a /= 10;
  14.     ch3 = a % 10;
  15.  
  16.     if (ch3)
  17.         n = 3;
  18.     else if (ch2)
  19.         n = 2;
  20.     else if (ch1)
  21.         n = 1;
  22.     else
  23.         n = 0;
  24.  
  25.     cout << "n: " << n << endl;
  26.     cout << "s: " << ch1 + ch2 + ch3 << endl;
  27. }
  28.  
  29. void nums2() {
  30.     int a = 768;
  31.     int s =0; // для суммы
  32.     int n = 0;             // это для кол.-ва цифр
  33.  
  34.     if (a)
  35.         n += 1;
  36.     s += a % 10;
  37.     a /= 10;
  38.    
  39.     if (a)
  40.         n += 1;  // n = n + 1
  41.     s += a % 10; // s = s + (a % 10)
  42.     a /= 10;     // a = a / 10
  43.    
  44.     if (a)
  45.         n += 1;
  46.     s += a % 10;
  47.  
  48.     cout << "n: " << n << endl;
  49.     cout << "s: " << s << endl;
  50. }
  51.  
  52.  
  53. void test_incr() {
  54.     int x = 0;
  55.     int y = x++;
  56.     cout << y << x << endl;
  57.     x++;
  58.     cout << x << endl;
  59.     cout << x++ << endl;
  60.     cout << x << endl;
  61.  
  62.     int p = 0;
  63.     int q = ++p;
  64.     cout << q << p << endl;
  65.     ++p;
  66.     cout << p << endl;
  67.     cout << ++p << endl;
  68.     cout << p << endl;
  69.     cout << ++++++++p << endl;
  70. }
  71.  
  72. void test_while1() {
  73.     int iter = 0;
  74.     while (iter < 10) {
  75.         ++iter;
  76.         cout << iter << ' ';
  77.         //cout << "Hello" << endl;
  78.     }  
  79. }
  80.  
  81. void test_sum() {
  82.     // 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
  83.     // 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 = ???
  84.     int sum = 0, k = 1, num = 10;
  85.     int prod = 1;
  86.     while (k <= num) {     
  87.         sum += k;
  88.         prod *= k;
  89.         ++k;
  90.     }
  91.  
  92.     int n = 0;
  93.     while (n < num-1/*10*/) {
  94.         n++;
  95.         cout << n;
  96.         cout << " + ";
  97.         /*if (n < 10)
  98.             cout << " + "; 
  99.         else
  100.             cout << " = ";*/
  101.     }
  102.     cout << ++n << " = ";
  103.     cout << sum << endl;
  104.     //cout << "prod: " << prod << endl;
  105. }
  106.  
  107. void test_line() {
  108.     int num = 8;
  109.     bool is_horizontal = 0;
  110.  
  111.     int k = 0;
  112.     if(is_horizontal)
  113.         while (k < num) {
  114.             cout << "#";
  115.             k++;
  116.         }
  117.     else
  118.         while (k < num) {
  119.             cout << "#" << endl;
  120.             k++;
  121.         }
  122. }
  123.  
  124. void table_fun() {
  125.     double x = 0;
  126.     const double pi = 3.1415926;
  127.     while (x < 360) {
  128.         cout << x << "\t" << sin(x * pi / 180.0) << endl;
  129.         x += 5;
  130.     }
  131. }
  132.  
  133. int main() {
  134.     //test_line();
  135.     table_fun();
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement