Vladi1442

Untitled

Feb 17th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. //task 1
  8. /**/
  9. int max = INT_MIN;
  10. int min = INT_MAX;
  11.  
  12. cout << "Enter ten numbers: " << endl;
  13.  
  14. for(int i = 0; i < 10; i++){
  15. int number;
  16. cin >> number;
  17.  
  18. if(number > max){
  19. max = number;
  20. }
  21.  
  22. if(number < min){
  23. min = number;
  24. }
  25. }
  26.  
  27. cout << "Maximum of ten numbers is " << max << endl;
  28. cout << "Minimum of ten numbers is " << min << endl;
  29.  
  30. // task 2
  31.  
  32. int lowerCaseCount, upperCaseCount, digitCount, symbolCount;
  33.  
  34. lowerCaseCount = upperCaseCount = digitCount = symbolCount = 0;
  35.  
  36. cout << "Enter ten characters: " << endl;
  37.  
  38. for(int i = 0; i < 10; i++){
  39. char character;
  40. cin >> character;
  41.  
  42. if(character >= 'a' && character <= 'z'){
  43. lowerCaseCount++;
  44. } else if(character >= 'A' && character <= 'Z'){
  45. upperCaseCount++;
  46. } else if(character >= '0' && character <= '9'){
  47. digitCount++;
  48. } else {
  49. symbolCount++;
  50. }
  51. }
  52.  
  53. cout << "Lower cases: " << lowerCaseCount << endl;
  54. cout << "Upper cases: " << upperCaseCount << endl;
  55. cout << "Digits: " << digitCount << endl;
  56. cout << "Symbols: " << symbolCount << endl;
  57.  
  58. // task 3
  59.  
  60. cout << "Here we are gonna print all the consonants: " << endl;
  61.  
  62. for(int i = 'A'; i <= 'Z'; i++){
  63. bool isConsonant = !(i == 'A' || i == 'E' || i == 'I' || i == 'U' || i == 'O');
  64.  
  65. if(isConsonant){
  66. cout << (char)i << " ";
  67. }
  68. }
  69.  
  70. // task 4
  71.  
  72. int number;
  73. cout << "Enter a number: " << endl;
  74. cin >> number;
  75. int num = 1;
  76. cout << num;
  77. for(int i = 1; i < number; i++){
  78. num = num * 10 + 1;
  79. cout << " + " << num;
  80. }
  81.  
  82. // task 5
  83.  
  84. int number;
  85. cout << "Enter a number: " << endl;
  86. cin >> number;
  87. int temp = number, firstDigit, lastDigit = number % 10;
  88. while(temp != 0){
  89. if(temp < 10){
  90. temp = firstDigit;
  91. }
  92. temp /= 10;
  93. }
  94.  
  95. cout << "The first digit of a number is " << firstDigit << endl;
  96. cout << "The last digit of a number is " << lastDigit << endl;
  97.  
  98. if(firstDigit == lastDigit){
  99. cout << "The digits are equal." << endl;
  100. } else {
  101. cout << "The digits are not equal. " << endl;
  102. }
  103.  
  104. // task 6
  105.  
  106. int number;
  107. cin >> number;
  108. for(int i = 2; i < number / 2; i++){
  109. if(number % i == 0){
  110. bool flag = true;
  111. for(int j = 2; j < i / 2; j++){
  112. if(i % j == 0){
  113. flag = false;
  114. }
  115. }
  116. if(flag){
  117. cout << i << " ";
  118. }
  119. }
  120. }
  121.  
  122. // task 7
  123.  
  124. double a, b, c;
  125. for(size_t i = 1; i <= 50; i++){
  126. c = i;
  127. for(size_t j = 1; j <= 50; j++){
  128. b = j;
  129. for(size_t k = 1; k <= 50; k++){
  130. a = k;
  131. if(c * c * c == a * a + b * b){
  132. cout << a << " ," << b << " ," << c << endl;
  133. }
  134. }
  135. }
  136. }
  137.  
  138. // task 8
  139.  
  140. int x, y, x1, y1, radius;
  141. cin >> x >> y >> x1 >> y1 >> radius;
  142. bool isInCircle = ((x - x1) * (x - x1) + (y - y1) * (y - y1)) <= radius * radius;
  143. cout << boolalpha << isInCircle << endl;
  144.  
  145.  
  146. // task 9
  147.  
  148. int low, high;
  149. bool isPrime = true;
  150. cout << "Enter an interval: " << endl;
  151. cin >> low >> high;
  152.  
  153. while(low < high){
  154. isPrime = true;
  155. if(low == 0 || low == 1){
  156. isPrime = false;
  157. }
  158.  
  159. for(int i = 2; i < low / 2; i++){
  160. if(low % i == 0){
  161. isPrime = false;
  162. break;
  163. }
  164. }
  165.  
  166. if(isPrime){
  167. cout << low << " ";
  168. }
  169. low++;
  170. }
  171.  
  172. // task 10
  173.  
  174. int number, binary_number = 0, d = 1;
  175. cout << "Enter a number: " << endl;
  176. cin >> number;
  177.  
  178. if(number < 0 || number > 1000){
  179. cout << "You'll gonna get the error!" << endl;
  180. } else {
  181. while(number != 0){
  182. binary_number += (number % 2) * d;
  183. d *= 10;
  184. number /= 2;
  185. }
  186. }
  187.  
  188. cout << binary_number << endl;
  189. return 0;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment