Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub 1:
- 1.a
- 2.
- a)m=3
- b)10000,11110,12222,13333,...19999-10 valori
- c)
- citeste n
- k<-1
- m<-1
- daca n>9 atunci
- repeta
- daca n%10=n/10%10 atunci
- k=k+1
- daca k>m atunci
- m<-k
- sfdaca
- altfel
- k<-1
- sfdaca
- n<-n/10
- pana cand n<9
- sfrepeta
- sfdaca
- scrie m
- d)
- #include<iostream>
- using namespace std;
- int main()
- {
- int n;
- cout << "n="; cin >> n;
- int k = 1, m = 1;
- while (n > 9)
- {
- if (n % 10 == n / 10 % 10)
- {
- k++;
- if (k > m)
- m = k;
- }
- else
- k = 1;
- n /= 10;
- }
- cout << m;
- cout << endl << endl;
- system("pause");
- return 0;
- }
- sub2:
- 1.d
- 2.
- 3. 2 3 1 7
- 4.s=0;
- for(int i=0;i<20;i++)
- s+=p[i].pretOra*nrLocuriInchiriate;
- 5.#include <iostream>
- using namespace std;
- int main()
- {
- char cuvinte[100][20];
- int n, m;
- cout << "nr cuvinte: ";
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cout << "cuvant " << i + 1 << ":";
- cin >> cuvinte[i];
- }
- cout << "lungime cuvinte:";
- cin >> m;
- for (int i = 0; i < n; i++)
- if (strlen(cuvinte[i]) == m)
- cout << cuvinte[i] << " ";
- for (int i = 0; i < n; i++)
- if (strlen(cuvinte[i]) != m)
- cout << cuvinte[i] << " ";
- cout << endl << endl;
- system("pause");
- return 0;
- }
- sub3:
- 1.b
- 2.010011
- 010100
- 3.
- #include<iostream>
- #include<string>
- using namespace std;
- bool prim(int n)
- {
- if (n == 1)
- return false;
- if (n == 2)
- return true;
- if (n % 2 == 0)
- return false;
- for (int i = 3; i <= sqrt(n); i += 2)
- if (n%i == 0)
- return false;
- return true;
- }
- int minDivPrim(int n)
- {
- int min = 1;
- for (int i = 2; i <=n; i++)
- if (prim(i) && n%i == 0)
- min *= i;
- return min;
- }
- int main()
- {
- int n;
- cout << "n=";cin>>n;
- cout << minDivPrim(n);
- cout << endl << endl;
- system("pause");
- return 0;
- }
- 4.
- #include<iostream>
- using namespace std;
- int f(unsigned n)
- {
- if (n == 1)
- return 1;
- else
- if (n == 2)
- return -1;
- else
- return 1 - 2 * f(n - 1) - f(n - 2);
- }
- void afisare(int n)
- {
- for (int i = n; i >= 1; i--)
- cout << f(i) << " ";
- }
- int main()
- {
- int n;
- cout << "n="; cin >> n;
- afisare(n);
- cout << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement