Advertisement
Yanislav29

Untitled

Nov 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. // задача 1 от сборнита стр.182
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.  
  11. int n, max;
  12. int number[10];
  13. cout << "Enter number of elements you want:";
  14. cin >> n;
  15.  
  16. for (int i = 0; i < n; i++) { // цикъл с който определяме броя на желаните числа.
  17. cout << "Enter Element " << (i + 1) << " : ";
  18. cin >> number[i];
  19. }
  20.  
  21. max = number[0];
  22. for (int i = 0; i < n; i++)// тук присвояваме максималната стойност.
  23. {
  24. if (max < number[i]) {
  25. max = number[i];
  26. }
  27. }
  28.  
  29. cout << "The biggest number is :" << max << endl;
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. return 0;
  37. }
  38. #include "pch.h"
  39.  
  40.  
  41.  
  42. #include<iostream>
  43. // задача номер 2 от сборника стр.182
  44.  
  45. using namespace std;
  46. void main()
  47. {
  48. int number;
  49. int curnum;
  50. int Counter[3]{ 0,0,0 };
  51.  
  52. cout << "Enter number:";
  53. cin >> number;
  54.  
  55. do {
  56.  
  57.  
  58. curnum = number % 10;
  59. number = number / 10;
  60. Counter[curnum]++;
  61. } while (number > 0);
  62. for (int i = 0; i < 3; i++){
  63.  
  64. cout << " Number " << i << "/" << Counter[i] << endl;
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }
  74. // zadacha 3 ot zbornika str.182
  75. #include <iostream>
  76. #include <string>
  77. using namespace std;
  78. int main()
  79. {
  80. int size = 20;
  81. int p = 3;
  82. int q = 13;
  83. int cnt = 0;
  84. int arr[size];
  85.  
  86. for (int i = 0; i <= size; i++)
  87. {
  88. arr[i] = i + 1;
  89.  
  90. }
  91. for (int i = 0; i <= size; i++)
  92. {
  93. if (arr[i] >= p && arr[i] <= q) {
  94.  
  95. if (i % 2 != 0) {
  96. if (arr[i] % 2 == 0) {
  97.  
  98. cnt++;
  99. cout << arr[i] << " ";
  100. }
  101.  
  102.  
  103. }
  104.  
  105. }
  106. }
  107. cout << cnt;
  108. return 0;
  109. }
  110. // zadacha 4 ot zbornika str.182
  111. //
  112.  
  113. #include "pch.h"
  114. #include <iostream>
  115. using namespace std;
  116.  
  117. int main()
  118. {
  119. const int array_size = 10;
  120.  
  121. int num[array_size];
  122. int searchKey, searchedIndex, i;
  123. bool valueFound;
  124.  
  125. for (i = 0; i < array_size;i++) {
  126. cout << "Input the number :";
  127. cin >> num[i];
  128. }
  129. cout << endl;
  130. for ( i = 0; i < array_size; i++)
  131. {
  132. cout << num[i] << endl;
  133. }
  134. cout << endl;
  135. cout << " Enter The Value to search :";
  136. cin >> searchKey;
  137. cout << endl;
  138. valueFound = false;
  139.  
  140. for (i = 0; (i < array_size) && !valueFound;i++) {
  141.  
  142. if (searchKey == num[i]) {
  143. searchedIndex = i;
  144. valueFound = true;
  145. }
  146.  
  147. }
  148. if (valueFound) {
  149. cout << " Value found at index :: " << searchedIndex << endl;
  150. }
  151. else {
  152. cout << "Value not found" << endl;
  153.  
  154. }
  155. //izpalnenie na uslovie A i B podtocka
  156. cout << num[0] << endl;
  157. cout << num[9] << endl;
  158. return 0;
  159. }
  160. задача номер 5 от сб. стр. 182:
  161.  
  162. // Masivi.cpp : This file contains the 'main' function. Program execution begins and ends there.
  163. //
  164.  
  165.  
  166. #include <iostream>
  167. #include <cmath>
  168. using namespace std;
  169. int main()
  170. {
  171.  
  172. int n;
  173.  
  174. cin >> n;
  175. double arr[n];
  176. int result[n];
  177. if (n < 1 && n > 100) {
  178. cout << "You entered invalid number!" << endl;
  179. exit(0);
  180. }
  181. for (int i = 1;i < n;i++) {
  182. cout << "arr [ " << i << "] = ";
  183. cin >> arr[i];
  184. }
  185. for (int i = 1;i < n;i++) {
  186. if (arr[i] < i) {
  187. result[i] = pow(arr[i], 2);
  188. }
  189. if (arr[i] == i) {
  190. result[i] = arr[i] * (-1);
  191. }
  192. if (arr[i] > i) {
  193. result[i] = arr[i] - i;
  194. }
  195. }
  196. for (int i = 1;i < n;i++) {
  197. cout << result[i] << endl;
  198. }
  199. return 0;
  200. }
  201.  
  202. задача номер 6 сб. стр. 182.:
  203. // zadacha 6 ot zbornika
  204. //
  205.  
  206. #include "pch.h"
  207. #include <iostream>
  208. #include <cmath>
  209. using namespace std;
  210. int main()
  211. {
  212.  
  213. const int N = 5;
  214. int arr[N];
  215. for (int i = 0; i <N;i++) {
  216. cout << "arr[" << i << "] = ";
  217. cin >> arr[i];
  218. }
  219.  
  220. for (int i = 0;i < N;i++) {
  221. cout << arr[i] * i << "," << endl;
  222. }
  223. return 0;
  224. }
  225.  
  226. задача 7ма от сб.стр.182:
  227. // zadacha 7ot zbornika
  228. //
  229.  
  230. #include "pch.h"
  231. #include <iostream>
  232. #include <cmath>
  233. #include <stdlib.h>
  234. #include <stdio.h>
  235. #include <time.h>
  236. using namespace std;
  237. int main()
  238. {
  239.  
  240. const int N = 5;
  241. int arr[N];
  242. for (int i = 0; i <N;i++) {
  243. cout << "arr[" << i << "] = ";
  244. cin >> arr[i];
  245. }
  246. for (int i = 0;i < N;i++) { //izpalnenie na poduslovie A
  247. cout << arr[N - 1 - i] << ",";
  248. }
  249. for (int i = 0;i < N;i++) {//izpalnenie na poduslovie B
  250. if (arr[i] % 2 == 0) {
  251. cout << "Chetni stoinosti:" << endl;
  252. cout << arr[i] << "," << endl;
  253. }
  254. }
  255. for (int i = 0;i < N;i++) {
  256. if (arr[i] % 2 !=0) {
  257. cout << "Nechetni stoinosti:" << endl;
  258. cout << arr[i] << "," << endl;
  259. }
  260. }
  261. srand((unsigned)time(NULL));//izpulnenie na poduslovie C
  262.  
  263. for (int i = 0;i < N;i++) {
  264.  
  265. arr[i] = rand();
  266. cout << "Random numbers:" << endl;
  267. cout << arr[i] << "," << endl;
  268.  
  269. }
  270.  
  271. return 0;
  272. }
  273. задача 11 от сборника стр.183:
  274. // zadacha 11 ot zbornika
  275. //
  276.  
  277. #include "pch.h"
  278. #include <iostream>
  279.  
  280.  
  281. using namespace std;
  282. int main()
  283. {
  284.  
  285. const int N = 5;
  286. int arr[N];
  287. int y[N];
  288. int max = arr[0];
  289. int min = arr[0];
  290. int maxY = y[0];
  291. int minY = y[0];
  292. int c[N];
  293.  
  294. for (int i = 0; i <N;i++) {
  295. cout << "arr[" << i << "] = ";
  296. cin >> arr[i];
  297. }
  298. for (int i = 0; i < N;i++) {
  299. cout << "y[" << i << "] = ";
  300. cin >> y[i];
  301. }
  302. for (int i = 0; i < N;i++) {
  303.  
  304. if (arr[i] > y[i]) {
  305.  
  306. if (arr[i] > y[i] + 2) {
  307. max = arr[i];
  308. }
  309. }
  310. if (arr[i] <= y[i]) {
  311. if (arr[i] * arr[i] + 3 <= y[i] + 1) {
  312. min = y[i];
  313. }
  314. }
  315. }
  316. for (int i = 0;i < N;i++) {
  317. if (arr[i] > y[i]) {
  318. c[i] = max;
  319. }
  320. else {
  321. c[i] = min;
  322. }
  323. cout << c[i] << endl;
  324. }
  325. return 0;
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement