Home c++ Task with a cycle with a post-C++

# Task with a cycle with a post-C++

Author

Date

Category

Make a program for the output of all three-digit numbers, the amount of numbers of which is equal to this natural number. In solving the problem, it is necessary to use a cycle with a detonation

``````# include "PCH.H"
#Include & lt; iostream & gt;
Using Namespace STD;
INT MAIN ()
{
INT Z, Y, X, N, I;
SETLOCALE (LC_ALL, "RUS");
COUT & LT; & LT; "\ N. Natural N:";
CIN & GT; & GT; n;
z = y = i = 0;
x = 1;
do.
{
if (n = x + y + z) cout & lt; & lt; "\ NKVV X, Y, Z" & LT; & LT; x * 100 + y * 10 + z;
Z ++;
if (z = 10) y ++, z = 0;
if (y = 10) x ++, y = 0;
COUT & LT; & LT; "\ NKVV z" & lt; & lt; z;
COUT & LT; & LT; "\ NKVV Y" & lt; & lt; y;
COUT & LT; & LT; "\ NKVV X" & lt; & lt; x;
}
While (x & lt; = 10);
}
``````

## Answer 1

You can not bother not so much:

``````size_t digitsum (Size_t Number)
{
Size_t Sum {0};
While (Number & gt; 0)
{
SUM + = NUMBER% 10;
Number / = 10;
}
Return Sum;
}
INT MAIN ()
{
Size_t Requested_sum {0};
STD :: CIN & GT; & GT; Requested_sum;
Size_t Number {100};
do.
{
If (Digitsum (Number) == Requested_SUM) {
STD :: COUT & LT; & LT; Number & lt; & lt; STD :: ENDL;
}
Number ++;
} While (Number & LT; 1000);
Return 0;
}
``````

And yes, as surely noticed in the comments, do not be confused `= `and `== `🙂

## Answer 2

``````int x = 0, y = 0, n, k;
if (CIN & GT; & gt; n) {// if the specified number
do {
CIN & GT; & GT; k;
x = k / 100;
if (x & amp; & amp;! (x / 10)) {// If a three-digit number is introduced
y = k / 10; // Second digit
IF (x + y% 10 + k% 10 == n)
COUT & LT; & LT; "Number" & lt; & lt; k & lt; & lt; "Satisfies the requirement \ n";
}
} While (CIN); // While the number has been introduced
}
``````

# Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.