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

Write an expression that is equivalent to 4(x + 1) - 7 (x + 3)
Write an equation that represents the line plsss
What is the equation of the line shown in the coordinate plane below?
MULTIPLE CHOICE QUESTION The correct order from least to greatest is... 8/25, 38% 0.41 38% 8725, 0.41 0.41,8/25, 38%​
pi(r^2)(12)=324 , how do you find the radius of this equation? ​
A grocery store has 164 shelves for bottled goods. Each shelf can hold 23 bottles. How many bottles will the shelves hold in all?
Write a recursive formula for a_n,the n th term of the sequence 96,−24,6,....
can i have help please NO LINKS!!​
Find the equation of the line passes through the points (-1,5) and (3,13)
Hello could someone help me will name brainliest. No links please