cristimdaniel cristimdaniel
  • 11-05-2019
  • Computers and Technology
contestada

Make a program (C++). Sum of a 4 digits number and eliminating last digitsȘ

E.g: x=2347 -> 347+47+7=401

Respuesta :

tonb
tonb tonb
  • 12-05-2019

Answer:

#include <iostream>

#include <string>  

int GetEliminationSum(int number)

{

int sum = 0;

std::string s = std::to_string(number);

while (s.length() > 1)

{

 s = s.substr(1);

 sum += std::stoi(s);  

}

return sum;

}

int main()

{

   std::cout << "Enter your 4-digit number: ";

int number;

std::cin >> number;

std::cout << "The elimination sum is " << GetEliminationSum(number);

}

Explanation:

Answer Link

Otras preguntas

Find the greatest number of six digit which is a perfect square.
Simplify: [5-3x+2y-(2x-y)]-(3x -7y+9)
simplify the equation simplify x^5/8/x^1/6
eric has been donating books he no longer needs to his local library. after 3 months of donating, he had 157 books left in his room. after 8 months of donating,
Which word correctly completes the sentence? _______ turn is it to do the washing up? 1. Who’s 2. Whose 3. Whom 4. Which
a nucleotide of dna may contain?
Can I have the formula to solve the algebra problem more easy 56x2+104x+48=0
What happens when a glass rod is dipped in HCl and is brought near ammonia gas?
If The dimensions of a brick that weighs 25N are 0.19m x 0.07m x 0.095m. What pressure does the brick exert on the ground if it is resting on its largest face?
Can I have the formula to solve the algebra problem more easy 56x2+104x+48=0