urmatoarele ex (a 8-a)
Răspunsuri la întrebare
Răspuns:
1.
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
int s = 0;
int p = 1;
while (x) {
int u = x % 10;
if (u % 2 == 1) s += u, p *= u;
x /= 10;
}
cout << s << " " << p;
return 0;
}
2.
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int s = 0;
while (n) {
s = s + (n % 10) * (n % 10);
n /= 10;
}
cout << s;
return 0;
}
3.
#include<iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int p = 1;
while (a) {
p = a % 10 * p;
a /= 10;
}
if (p == b) cout << "DA";
else cout << "NU";
return 0;
}
4.
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int pare = 0;
int impare = 0;
while (n)
{
int u = n % 10;
if (u % 2 == 0) pare++;
else impare++;
n /= 10;
}
if (pare == impare) cout << "DA";
else cout << "NU";
return 0;
}
5.
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
int mx = 0;
while (x)
{
int u = x % 10;
if (u > mx) mx = u;
x /= 10;
}
cout << mx;
return 0;
}
6.
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
int mn = 999;
while (x)
{
int u = x % 10;
if (u < mn) mn = u;
x /= 10;
}
cout << mn;
return 0;
}
Explicație: