Advertisement
monyca98

model 2016

Feb 28th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. sub 1:
  2. 1.a
  3. 2.
  4. a)m=3
  5. b)10000,11110,12222,13333,...19999-10 valori
  6. c)
  7.     citeste n
  8.     k<-1
  9.     m<-1
  10.         daca n>9 atunci
  11.             repeta
  12.                 daca n%10=n/10%10 atunci
  13.                     k=k+1
  14.                     daca k>m atunci
  15.                         m<-k
  16.                     sfdaca
  17.                 altfel
  18.                     k<-1
  19.                 sfdaca
  20.                 n<-n/10
  21.             pana cand n<9
  22.             sfrepeta
  23.         sfdaca
  24.         scrie m
  25. d)
  26. #include<iostream>
  27. using namespace std;
  28. int main()
  29. {
  30.     int n;
  31.     cout << "n="; cin >> n;
  32.     int k = 1, m = 1;
  33.     while (n > 9)
  34.     {
  35.         if (n % 10 == n / 10 % 10)
  36.         {
  37.             k++;
  38.             if (k > m)
  39.                 m = k;
  40.         }
  41.         else
  42.             k = 1;
  43.         n /= 10;
  44.     }
  45.     cout << m;
  46.     cout << endl << endl;
  47.     system("pause");
  48.     return 0;
  49. }
  50. sub2:
  51. 1.d
  52. 2.
  53. 3. 2 3 1 7
  54. 4.s=0;
  55. for(int i=0;i<20;i++)
  56. s+=p[i].pretOra*nrLocuriInchiriate;
  57.  
  58. 5.#include <iostream>
  59. using namespace std;
  60.  
  61. int main()
  62. {
  63.     char cuvinte[100][20];
  64.     int n, m;
  65.  
  66.     cout << "nr cuvinte: ";
  67.     cin >> n;
  68.  
  69.     for (int i = 0; i < n; i++)
  70.     {
  71.         cout << "cuvant " << i + 1 << ":";
  72.         cin >> cuvinte[i];
  73.     }
  74.  
  75.     cout << "lungime cuvinte:";
  76.     cin >> m;
  77.  
  78.     for (int i = 0; i < n; i++)
  79.         if (strlen(cuvinte[i]) == m)
  80.             cout << cuvinte[i] << " ";
  81.  
  82.     for (int i = 0; i < n; i++)
  83.         if (strlen(cuvinte[i]) != m)
  84.             cout << cuvinte[i] << " ";
  85.  
  86.     cout << endl << endl;
  87.     system("pause");
  88.     return 0;
  89. }
  90. sub3:
  91. 1.b
  92. 2.010011
  93.   010100
  94. 3.
  95. #include<iostream>
  96. #include<string>
  97. using namespace std;
  98. bool prim(int n)
  99. {
  100.     if (n == 1)
  101.         return false;
  102.     if (n == 2)
  103.         return true;
  104.     if (n % 2 == 0)
  105.         return false;
  106.     for (int i = 3; i <= sqrt(n); i += 2)
  107.         if (n%i == 0)
  108.             return false;
  109.     return true;
  110. }
  111. int minDivPrim(int n)
  112. {
  113.     int min = 1;
  114.     for (int i = 2; i <=n; i++)
  115.         if (prim(i) && n%i == 0)
  116.             min *= i;
  117.     return min;
  118. }
  119. int main()
  120. {
  121.     int n;
  122.     cout << "n=";cin>>n;
  123.     cout << minDivPrim(n);
  124.     cout << endl << endl;
  125.     system("pause");
  126.     return 0;
  127. }
  128. 4.
  129. #include<iostream>
  130. using namespace std;
  131. int f(unsigned n)
  132. {
  133.     if (n == 1)
  134.         return 1;
  135.     else
  136.         if (n == 2)
  137.             return -1;
  138.         else
  139.             return 1 - 2 * f(n - 1) - f(n - 2);
  140. }
  141. void afisare(int n)
  142. {
  143.     for (int i = n; i >= 1; i--)
  144.         cout << f(i) << " ";
  145. }
  146. int main()
  147. {
  148.     int n;
  149.     cout << "n="; cin >> n;
  150.     afisare(n);
  151.  
  152.     cout << endl << endl;
  153.     system("pause");
  154.     return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement