Răspuns :
Salut!
Ai rezolvarile la toate problemele in C++ mai jos
1.
#include <iostream>
using namespace std;
int fact(int n)
{
if (n == 1)
{
return 1;
}
return n * fact(n-1);
}
int main()
{
int n, factorial, s = 0;
cin >> n;
factorial = fact(n);
while (factorial)
{
s += factorial % 10;
factorial /= 10;
}
cout << s;
return 0;
}
2.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a[20];
int l;
bool ok = false;
cin >> a;
l = strlen(a);
if (strchr("aeiouAEIOU", a[0]))
{
if (strchr("aeiouAEIOU", a[l]))
{
ok = true;
}
}
if (ok)
{
cout << "DA";
}
else
{
cout << "NU";
}
return 0;
}
3.
#include <iostream>
using namespace std;
struct punct
{
int abscisa;
int ordonata;
};
int main()
{
int n, cntx = 0, cnty = 0;
punct a[10001];
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].abscisa >> a[i].ordonata;
if (a[i].abscisa == 0)
{
cntx++;
}
if (a[i].abscisa == a[i].ordonata)
{
cnty++;
}
}
cout << "Ox: " << cntx << '\n';
cout << "Oy: " << cnty;
return 0;
}
4.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a[256], sep[] = " ", m[20][1001];
cin.getline(a, 256);
int ind = 0, cnt = 0;
char *p = strtok(a, sep);
while (p)
{
strcpy(m[++ind], p);
p = strtok(NULL, sep);
}
for (int i = 1; i <= ind; ++i)
{
if (strchr(m[i], 'a'))
{
cnt++;
}
}
cout << cnt;
return 0;
}
5.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("date.in");
int main()
{
int n, cnt = 0;
while (in >> n)
{
if (n % 10 == n / 10 % 10)
{
cnt++;
}
}
cout << cnt;
in.close();
return 0;
}