Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[1000], n, b[1000], m;
- //1.Citirea vect.
- void Read(int t[], int &n)
- {
- cin >> n;
- for(int i = 0; i < n; i++)
- {
- cout << "[" << i << "] = ";
- cin >> t[i];
- }
- cout << "\n";
- }
- //2.Ordonarea vect.
- void Desc(int a[], int n)
- {
- for(int i = 0; i < n-1; i++)
- for(int j = i+1; j < n; j++)
- if(a[i] < a[j])
- {
- int aux = a[i];
- a[i] = a[j];
- a[j] = aux;
- }
- }
- //3.Afisarea vect.
- void Print(int a[], int n)
- {
- for(int i = 0; i < n; i++)
- cout << a[i] << " ";
- cout << "\n";
- }
- //4.Afisarea elementelor comune
- void Comun(int a[], int n, int b[], int m)
- {
- int i = 0, j = 0, k;
- for(k = 0; (i < n)&&(j < m); k++)
- {
- if(a[i] == b[j])
- {
- cout << a[i] << " ";
- i++;
- j++;
- }
- else if(a[i] > b[j])
- i++;
- else j++;
- }
- }
- //*.Suma elementelor
- int Suma(int a[], int n)
- {
- int s = 0;
- for(int i = 0; i < n; i++)
- s += a[i];
- return s;
- }
- int main()
- {
- Read(a, n);
- Read(b, m);
- Desc(a, n);
- Desc(b, m);
- Print(a, n);
- Print (b, m);
- Comun(a, n, b, m);
- cout << Suma(a, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment