#include
using namespace std;
int main()
{
int n, m, n1;
int s=0;
int k=0;
cout << "n = ", cin >> n, cout << "\n";<br> cout << "m = ", cin >> m, cout << "\n";<br> n1 = n;
while (n1 > 0){
s += n1 % 10;
n1 = n1 / 10;
k++;
}
n1 = n;
for (int i=1; i<=k-m; i++) {<br> s -= n1 % 10;
n1 = n1 / 10;
}
cout << "s = " << s << "\n";<br> return 0;
}
Пример:
n = 34568
m = 4
s = 18