Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Suma nr imp
- int Impar(int a[], int n, int i)
- {
- if(i == n) return 0;
- if(n % 2 == 1) return a[i] + Impar(a, n, i+1);
- return 0 + Impar(a, n, i+1);
- }
- //Elimin cif 0
- /*int Cif0(int n)
- {
- int s = 0, nr = 1;
- while(n)
- {
- if(n % 10 == 0)
- {
- ...
- }
- }
- }*/
- //Fc. recurs. care afis. n in baza 2
- void Baza2(int n)
- {
- if (n > 0)
- {
- Baza2(n / 2);
- cout << n % 2;
- }
- }
- int main()
- {
- Baza2(1024);
- return 0;
- }
- //t2
- #include <iostream>
- using namespace std;
- int a[10001], k;
- void Baza2(int n)
- {
- if (n > 0)
- {
- Baza2(n / 2);
- cout << n % 2;
- }
- }
- void Citire_Vector(int n)
- {
- int i;
- for (i = 1; i <= n; i++)
- cin >> a[i];
- }
- int Putere_Lui_2(int n)
- {
- int nr, k, i, d, j;
- nr = 0;
- for (i = 1; i <= n; i++)
- {
- d = 0;
- j = 0;
- k = (1 << j);
- while (a[i] >= k)
- {
- k = (1 << j);
- if (k == a[i])
- d = 1;
- j++;
- }
- if (d == 1)
- nr++;
- }
- return nr;
- }
- void Sch(int &x, int &y)
- {
- int aux;
- aux = x;
- x = y;
- y = aux;
- }
- int Pivot(int st, int dr)
- {
- int piv, i, j;
- piv = a[st];
- i = st + 1;
- j = dr;
- while (i < j)
- {
- if (a[i] < piv)
- i++;
- else if (a[j] > piv)
- j--;
- else if (i <= j a[i] > piv && piv > a[j])
- Sch(a[i], a[j]);
- }
- Sch(a[i-1], a[st]);
- return i - 1;
- }
- int Kelement(int st, int dr, int k)
- {
- int m = Pivot(st, dr);
- if (m == k) return a[m];
- if ()
- }
- int main()
- {
- int n;
- /*cout << "N = ";
- cin >> n;
- Baza2(n);
- cout << "\n\n";
- cout << "N = ";
- cin >> n;
- Citire_Vector(n);
- cout << Putere_Lui_2(n) << "\n\n";*/
- cout << "K = ";
- cin >> k;
- cout << "N = ";
- cin >> n;
- Citire_Vector(n);
- cout << Pivot(1, n);
- for (int i = 1; i <= n; i++)
- cout << a[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement