Răspuns :
Problema 1
C++
#include <iostream>
using namespace std;
int main()
{
int n, sum = 0, m, numara = 0;
cin >> n;
while (n > 0)
{
m = n % 10;
sum = sum + m;
n = n / 10;
}
while (sum > 0)
{
sum = sum / 10;
numara++;
}
cout << numara;
return 0;
}
PSEUDOCOD
start
natural n, sum, m, numara
sum <- 0
numara <- 0
scrie n
cat_timp n > 0
m <- n mod 10
sum <- sum + m
n <- n div 10
sfarsit_cat_timp
cat_timp sum > 0
sum <- sum div 10
numara <- numara + 1
sfarsit_cat_timp
scrie numara
stop
Problema 2
C++
#include <iostream>
using namespace std;
int main()
{
int n, nr_pare = 0, nr_impare = 0, m;
cin >> n;
while (n > 0)
{
m = n % 10;
if (n % 2 == 0)
{
nr_pare++;
}
else
{
nr_impare++;
}
n = n / 10;
}
cout << "pare = " << nr_pare << " impare = " << nr_impare;
return 0;
}
PSEUDOCOD
start
natural n, nr_pare, nr_impare, m
scrie n
nr_pare <- 0
nr_impare <- 0
cat_timp n > 0
m <- n mod 10
daca n mod 2 = 0
atunci
nr_pare <- nr_pare + 1
sfarsit_daca
altfel
nr_impare <- nr_impare + 1
sfarsit_altfel
n <- n div 10
sfarsit_cat_timp
scrie pare = nr_pare impare = nr_impare