Kaloyankerr

SchoolHW №1

Mar 5th, 2021 (edited)
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 KB | None | 0 0
  1. Задача 1)
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {   
  6.     int n;
  7.     cin >> n;
  8.    
  9.     for (int i = 1; i <= n; i++){
  10.         cout << i << endl;
  11.     }
  12.   return 0;
  13. }
  14. ========================================================
  15. Задача 2)
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main()
  20. {  
  21.     cout << "Dec   Char" << endl;
  22.     for (int i = 0; i <= 127; i++){
  23.         cout << i << "   = " << char(i) << endl;
  24.     }
  25. }
  26. ========================================================
  27. Задача 3)
  28. #include <iostream>
  29. using namespace std;
  30.  
  31. int main()
  32. {  
  33.     int n;
  34.     cout << "Number: ";
  35.     cin >> n;
  36.    
  37.     for (int i = 1; i < n; i++) {
  38.         if (i % 2 == 0){
  39.             cout << i << endl;
  40.         }
  41.     }
  42. }
  43. ========================================================
  44. Задача 4)
  45. #include <iostream>
  46. using namespace std;
  47.  
  48. int main() {   
  49.     int a, b;
  50.     cin >> a;
  51.     cin >> b;
  52.    
  53.     for (a; a <= b; a++){
  54.         cout << a << endl;
  55.     }
  56.   return 0;
  57. }
  58. ========================================================
  59. Задача 5)
  60. #include <iostream>
  61. using namespace std;
  62.  
  63. int main() {   
  64.     int a, b, x;
  65.     cin >> a;
  66.     cin >> b;
  67.     cin >> x;
  68.    
  69.     for (a; a <= b; a++){
  70.         if (a % x == 0){
  71.             cout << a << endl;
  72.         }
  73.     }
  74.   return 0;
  75. }
  76. ========================================================
  77. Задача 6)
  78. #include <iostream>
  79. #include <string>
  80. #include <cmath>
  81. using namespace std;
  82.  
  83. int main() {
  84.     int n, sum_of_nums;
  85.    
  86.     cout << "Number n: ";
  87.     cin >> n;
  88.    
  89.     sum_of_nums = 0;
  90.    
  91.     for (int i = 1; i <= n; i++){
  92.         sum_of_nums += i;
  93.     }
  94.    
  95.     cout << "Sum of all numbers: " << sum_of_nums;
  96.     return 0;
  97. }
  98. ========================================================
  99. Задача 7)
  100. #include <iostream>
  101. #include <string>
  102. #include <cmath>
  103. using namespace std;
  104.  
  105. int main() {
  106.     int n, mul_of_nums;
  107.    
  108.     cout << "Number n: ";
  109.     cin >> n;
  110.    
  111.     mul_of_nums = 1;
  112.    
  113.     for (int i = 1; i <= n; i++){
  114.        
  115.         mul_of_nums *= i;
  116.     }
  117.    
  118.     cout << "Multiplication of all numbers: "<< mul_of_nums;
  119.     return 0;
  120. }
  121. ========================================================
  122. Задача 8)
  123. #include <iostream>
  124. #include <string>
  125. #include <cmath>
  126. #include <bits/stdc++.h>
  127. using namespace std;
  128.  
  129. int main() {
  130.     int n, num, sum_of_numbers, mul_of_numbers;
  131.     list <int> numbers;
  132.    
  133.     cout << "Enter numbers count: ";
  134.     cin >> n;
  135.    
  136.     for (int i = 0; i < n; i++){
  137.         cin >> num;
  138.         numbers.push_back(num);
  139.     }
  140.    
  141.     sum_of_numbers = accumulate(numbers.begin(), numbers.end(), 0);
  142.     mul_of_numbers = accumulate(numbers.begin(), numbers.end(), 1, multiplies<int>());
  143.     cout << "\nSum = " << sum_of_numbers << endl;
  144.     cout << "Multiplication = " << mul_of_numbers;
  145.    
  146.     return 0;
  147. }
  148. ========================================================
  149. Задача 9)
  150. #include <iostream>
  151. #include <string>
  152. #include <cmath>
  153. #include <iostream>
  154.  
  155. using namespace std;
  156. int main()
  157. {
  158.     int array[50];
  159.     int i, max, min, size, positive_count;
  160.    
  161.     cout<<"Enter size of the array: ";
  162.     cin>>size;
  163.    
  164.     cout<<"\nEnter "<<size <<" elements in the array: " << endl;
  165.     for(i=0; i<size; i++)
  166.         cin>>array[i];
  167.    
  168.     max = array[0];
  169.     min = array[0];
  170.     positive_count = 0;
  171.    
  172.     for(i=1; i<size; i++) {
  173.         if(array[i] > 0)
  174.             positive_count += 1;
  175.        
  176.         if(array[i] > max)
  177.             max = array[i];
  178.    
  179.         if(array[i] < min)
  180.             min = array[i];
  181.     }
  182.    
  183.     cout << "\nMaximum element: " << max << endl;
  184.     cout << "Minimum element: " << min << endl;
  185.     cout << "Positve numbers count: " << positive_count;
  186.     return 0;
  187.  
  188. }
  189.  
Add Comment
Please, Sign In to add comment