0% found this document useful (0 votes)
25 views5 pages

Ce - Tema

Uploaded by

Naomi Onofrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Ce - Tema

Uploaded by

Naomi Onofrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

21.

#include <iostream>
using namespace std;
int
main ()
{
int a[20], b[20], i, n;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
b[i] =0;
while (a[i]!=0)
{
b[i] = b[i] + a[i] % 10;
a[i] = a[i] / 10;
}
}
for (i = 1; i <= n; i++)
cout << b[i] << ' ';
}

22. #include <iostream>


using namespace std;
int
main ()
{
int a[20], b[20], i, n;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
b[i] = 0;
while (a[i] != 0)
{
b[i] = b[i] * 10 + a[i] % 10;
a[i] = a[i] / 10;
}
} for (i = 1; i <= n; i++)
cout << b[i] << ' ';
}
23.#include <iostream>
using namespace std;
int
main ()
{
int a[20], b[20], i, n;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
b[i] = -1;
while (a[i])
{
if (a[i] % 10 > b[i])
{
b[i] = a[i] % 10;
a[i] = a[i] / 10;
}
}
}
for (i = 1; i <= n; i++)
cout << b[i] << ' ';
}

24.#include <iostream>
using namespace std;
int
main ()
{
int a[20], b[20], c[20], i, n, Nr = 0;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
c[i] = a[i];
b[i] = 0;
while (a[i] != 0)
{
b[i] = b[i] * 10 + a[i] % 10;
a[i] = a[i] / 10;
}
if (b[i] ==c[i])
Nr++;
}

cout << Nr << ' ';


}

25. #include <iostream>


using namespace std;
int
main ()
{
int a[20], i, n, x = 0, d, nr; // x este nr de divizori/
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
for (d = 1; d <= a[i]; d++)
{
if (a[i] % d == 0)
{
x++;
}
}
if (x == 2)

nr++;
}
cout << nr;
}

29.#include <iostream>
using namespace std;
int
main ()
{
int a[20], b[20], i, n;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 0; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 0; i <= n; i++)
{
b[i] = a[n-i];
}
for (i = 0; i <= n; i++)
cout << b[i] << ' ';
}

30. #include <iostream>


using namespace std;
int
main ()
{
int a[20], i, n, x=1;
cout << "Introduceti nr de componente a vectorului a, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << "a[" << i << "]=";
cin >> a[i];
}
for (i = 1; i <= n; i++)
{
if (a[i] == a[i + 1])
x++;
if( a[i] = a[i - 1])
x++;
}
cout << x; //functioneaza bine numai daca nr care se repeta este unul singur
}

B1234.
#include <iostream>
using namespace std;
int
main ()
{
int a[20],i, n;
cout << "Introduceti nr de componente a vectorilor, n=";
cin >> n;
for (i = 1; i <= n; i++)
{
a[i] = i;
}
cout << "Sirul 1:";
for (i = 1; i <= n; i++)
cout << a[i] << ",";
cout << "Sirul 2:";
for (i = 1; i <= n; i++)
cout << 2*a[i] << ",";
cout << "Sirul 3:";
for (i = 1; i <= n; i++)
cout << a[i]<<","<<a[i] << ",";
cout << "Sirul 4:";
for (i = 1; i <= n; i++)
cout << a[i]<<",0,";

You might also like