Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- void create(int* x, int n)
- {
- int i;
- for (i = 0; i < n; i++)
- {
- cout << "x[" << i << "]=";
- cin >> x[i];
- }
- }
- void show(int* x, int n)
- {
- int i;
- for (i = 0; i < n; i++)
- cout << setw(10) << x[i];
- cout << endl;
- }
- bool prime(int x)
- {
- if (x <= 1)
- return false;
- if (x == 2) return true;
- int i;
- bool t = true;
- for (i = 2; i <= sqrt(x) && t; i++)
- if (x % i == 0)
- t = false;
- return t;
- }
- int summ(int* x, int n)
- {
- int s = 0;
- int i;
- for (i=0;i<n;i++)
- if(prime(x[i]))
- s=s+x[i];
- return s;
- }
- bool E(int* x, int n)
- {
- bool t = false;
- int i;
- for (i = 0; i < n && !t; i++)
- if (prime(x[i]))
- t = true;
- return t;
- }
- int max(int* x, int n)
- {
- int m=-5;
- int i;
- for (i = 0; i < n; i++)
- if (prime(x[i])&&( (m==-5)||(m<x[i])))
- {
- m = x[i];
- }
- return m;
- }
- int min(int* x, int n)
- {
- int m = -5;
- int i;
- for (i = 0; i < n; i++)
- if (prime(x[i]) && ((m == -5) || (m > x[i])))
- {
- m = x[i];
- }
- return m;
- }
- void shift_left(int* x, int n)
- {
- int r=x[0], i;
- for (i = 0; i < n - 1; i++)
- x[i] = x[i + 1];
- x[n - 1] = r;
- }
- void shift_right(int* x, int n)
- {
- int r = x[n-1], i;
- for (i = n-1; i>0; i--)
- x[i] = x[i - 1];
- x[0] = r;
- }
- void sort(int* x, int n)
- {
- int i, r;
- bool t = true;
- while (t)
- {
- t = false;
- for (i = 0; i < n - 1; i++)
- if (x[i] > x[i + 1])
- {
- t = true;
- r = x[i];
- x[i] = x[i + 1];
- x[i + 1] = r;
- }
- }
- }
- int SUMM(int x)
- {
- x = abs(x);
- int s = 0;
- while (x > 0)
- {
- s = s + x % 10;
- x = x / 10;
- }
- return s;
- }
- void vektor(int* x, int* y, int n)
- {
- int i;
- for (i = 0; i < n; i++)
- y[i] = SUMM(x[i]);
- }
- int main()
- {
- int i;
- int n;
- cout << "enter size of array a: n=";
- cin >> n;
- int* a = new int[n];
- cout << "enter array a:" << endl;
- create(a, n);
- cout << "array a:" << endl;
- show(a, n);
- if (E(a, n))
- cout << "max of prime number=" << max(a, n) << endl;
- else cout << "in massive net prostogo chisla" << endl;
- if (E(a, n))
- cout << "min of prime number=" << min(a, n) << endl;
- else cout << "in massive net prostogo chisla" << endl;
- shift_left(a, n);
- shift_right(a, n);
- cout << "array a':" << endl;
- show(a, n);
- sort(a, n);
- cout << "sort array a':" << endl;
- show(a, n);
- int* b = new int[n];
- vektor(a, b, n);
- cout << "array b:" << endl;
- show(b, n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement