Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // задача 1 от сборнита стр.182
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, max;
- int number[10];
- cout << "Enter number of elements you want:";
- cin >> n;
- for (int i = 0; i < n; i++) { // цикъл с който определяме броя на желаните числа.
- cout << "Enter Element " << (i + 1) << " : ";
- cin >> number[i];
- }
- max = number[0];
- for (int i = 0; i < n; i++)// тук присвояваме максималната стойност.
- {
- if (max < number[i]) {
- max = number[i];
- }
- }
- cout << "The biggest number is :" << max << endl;
- return 0;
- }
- #include "pch.h"
- #include<iostream>
- // задача номер 2 от сборника стр.182
- using namespace std;
- void main()
- {
- int number;
- int curnum;
- int Counter[3]{ 0,0,0 };
- cout << "Enter number:";
- cin >> number;
- do {
- curnum = number % 10;
- number = number / 10;
- Counter[curnum]++;
- } while (number > 0);
- for (int i = 0; i < 3; i++){
- cout << " Number " << i << "/" << Counter[i] << endl;
- }
- }
- // zadacha 3 ot zbornika str.182
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int size = 20;
- int p = 3;
- int q = 13;
- int cnt = 0;
- int arr[size];
- for (int i = 0; i <= size; i++)
- {
- arr[i] = i + 1;
- }
- for (int i = 0; i <= size; i++)
- {
- if (arr[i] >= p && arr[i] <= q) {
- if (i % 2 != 0) {
- if (arr[i] % 2 == 0) {
- cnt++;
- cout << arr[i] << " ";
- }
- }
- }
- }
- cout << cnt;
- return 0;
- }
- // zadacha 4 ot zbornika str.182
- //
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- const int array_size = 10;
- int num[array_size];
- int searchKey, searchedIndex, i;
- bool valueFound;
- for (i = 0; i < array_size;i++) {
- cout << "Input the number :";
- cin >> num[i];
- }
- cout << endl;
- for ( i = 0; i < array_size; i++)
- {
- cout << num[i] << endl;
- }
- cout << endl;
- cout << " Enter The Value to search :";
- cin >> searchKey;
- cout << endl;
- valueFound = false;
- for (i = 0; (i < array_size) && !valueFound;i++) {
- if (searchKey == num[i]) {
- searchedIndex = i;
- valueFound = true;
- }
- }
- if (valueFound) {
- cout << " Value found at index :: " << searchedIndex << endl;
- }
- else {
- cout << "Value not found" << endl;
- }
- //izpalnenie na uslovie A i B podtocka
- cout << num[0] << endl;
- cout << num[9] << endl;
- return 0;
- }
- задача номер 5 от сб. стр. 182:
- // Masivi.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- double arr[n];
- int result[n];
- if (n < 1 && n > 100) {
- cout << "You entered invalid number!" << endl;
- exit(0);
- }
- for (int i = 1;i < n;i++) {
- cout << "arr [ " << i << "] = ";
- cin >> arr[i];
- }
- for (int i = 1;i < n;i++) {
- if (arr[i] < i) {
- result[i] = pow(arr[i], 2);
- }
- if (arr[i] == i) {
- result[i] = arr[i] * (-1);
- }
- if (arr[i] > i) {
- result[i] = arr[i] - i;
- }
- }
- for (int i = 1;i < n;i++) {
- cout << result[i] << endl;
- }
- return 0;
- }
- задача номер 6 сб. стр. 182.:
- // zadacha 6 ot zbornika
- //
- #include "pch.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- const int N = 5;
- int arr[N];
- for (int i = 0; i <N;i++) {
- cout << "arr[" << i << "] = ";
- cin >> arr[i];
- }
- for (int i = 0;i < N;i++) {
- cout << arr[i] * i << "," << endl;
- }
- return 0;
- }
- задача 7ма от сб.стр.182:
- // zadacha 7ot zbornika
- //
- #include "pch.h"
- #include <iostream>
- #include <cmath>
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- const int N = 5;
- int arr[N];
- for (int i = 0; i <N;i++) {
- cout << "arr[" << i << "] = ";
- cin >> arr[i];
- }
- for (int i = 0;i < N;i++) { //izpalnenie na poduslovie A
- cout << arr[N - 1 - i] << ",";
- }
- for (int i = 0;i < N;i++) {//izpalnenie na poduslovie B
- if (arr[i] % 2 == 0) {
- cout << "Chetni stoinosti:" << endl;
- cout << arr[i] << "," << endl;
- }
- }
- for (int i = 0;i < N;i++) {
- if (arr[i] % 2 !=0) {
- cout << "Nechetni stoinosti:" << endl;
- cout << arr[i] << "," << endl;
- }
- }
- srand((unsigned)time(NULL));//izpulnenie na poduslovie C
- for (int i = 0;i < N;i++) {
- arr[i] = rand();
- cout << "Random numbers:" << endl;
- cout << arr[i] << "," << endl;
- }
- return 0;
- }
- задача 11 от сборника стр.183:
- // zadacha 11 ot zbornika
- //
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- const int N = 5;
- int arr[N];
- int y[N];
- int max = arr[0];
- int min = arr[0];
- int maxY = y[0];
- int minY = y[0];
- int c[N];
- for (int i = 0; i <N;i++) {
- cout << "arr[" << i << "] = ";
- cin >> arr[i];
- }
- for (int i = 0; i < N;i++) {
- cout << "y[" << i << "] = ";
- cin >> y[i];
- }
- for (int i = 0; i < N;i++) {
- if (arr[i] > y[i]) {
- if (arr[i] > y[i] + 2) {
- max = arr[i];
- }
- }
- if (arr[i] <= y[i]) {
- if (arr[i] * arr[i] + 3 <= y[i] + 1) {
- min = y[i];
- }
- }
- }
- for (int i = 0;i < N;i++) {
- if (arr[i] > y[i]) {
- c[i] = max;
- }
- else {
- c[i] = min;
- }
- cout << c[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement