Răspuns :
Salut!
Ai rezolvarile la cele 2 probleme mai jos in limbajul C++
1.
#include <iostream>
using namespace std;
int main()
{
int n, s = 0;
cin >> n;
while (n != 0)
{
int c = n % 10;
s += c;
n /= 10;
}
cout << s;
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n != 0)
{
int c = n % 10;
cout << c << " ";
n /= 10;
}
return 0;
}
Răspuns:
1.#include <iostream>
using namespace std;
int main()
{
int n, s=0, x;
cin>>n;
while(n!=0)
{
x=n%10;
s=s+x;
n=n/10;
}
cout<<s;
}
2.#include <iostream>
using namespace std;
int main()
{
int n, x;
cin>>n;
while(n!=0)
{
x=n%10;
cout<<x<<" ";
n=n/10;
}
}
Explicație: