PROBLEM WITH INTEGER SUM
-
Any suggestions?
-
I suspect for loop is having problems. How to fix it to generate sequence?
-
Hier sieht es verdächtig nach Spam aus. Jedenfalls wurde sich nicht an die normalen Verhaltensregeln gehalten, imho.
-
@EinNutzer0 sagte in PROBLEM WITH INTEGER SUM:
Hier sieht es verdächtig nach Spam aus. Jedenfalls wurde sich nicht an die normalen Verhaltensregeln gehalten, imho.
Ungewöhnlich, klar. Kann aber nix konkretes entdecken. Ob es bei der Qualität der Fragestellung eine Antwort geben wird, ist natürlich fraglich, aber da ist er bei weitem nicht der einzige.
-
@SeppJ sagte in PROBLEM WITH INTEGER SUM:
@EinNutzer0 sagte in PROBLEM WITH INTEGER SUM:
Hier sieht es verdächtig nach Spam aus. Jedenfalls wurde sich nicht an die normalen Verhaltensregeln gehalten, imho.
Ungewöhnlich, klar. Kann aber nix konkretes entdecken. Ob es bei der Qualität der Fragestellung eine Antwort geben wird, ist natürlich fraglich, aber da ist er bei weitem nicht der einzige.
Da hast du wahr.
Ich für meinen Teil helfe hierbei jedenfalls mal nicht, weil ich den unformatierten Code gar net lesen kann.
Andere mögen sich beteiligen.
-
How to add formatted code here? can anyone guide me here? I am new here.
-
@bugsfinder2022 sagte in PROBLEM WITH INTEGER SUM:
How to add formatted code here? can anyone guide me here? I am new here.
This forum, as most forums, uses a variation of the Markdown language. You can also use the formatting buttons above the edit window if you want to use a GUI instead of using special characters.
-
@bugsfinder2022 sagte in PROBLEM WITH INTEGER SUM:
How to add formatted code here?
you need THREE backticks before and after your code (you have TWO). Or just select your code and press the </> button.
-
To solve, consider calculating
number / 9
andnumber % 9
.Example 19:
19 / 9 = 2. You have two 9 at the end.
19 % 2 = 1. A 1 before.
=> 19921 / 9 = 2. Two 9s.
21 % 9 = 3. => 399
-
Modified code, but output is not expected value.
"""
class Test {public:
static int solve(int N)
{ int sum1 = 0;
while (N != 0)
{
sum1 += N % 10;
N /= 10;
}
return sum1;
}static void smallestnum(int N)
{
std::cout << (N % 9 + 1)
* pow(10, (N / 9))
- 1;}
};int main()
{
std::cout << Test::solve(16) << + " --> 79" << std::endl;
std::cout << Test::solve(19) << + " --> 199" << std::endl;
std::cout << Test::solve(7) << + " --> 7" << std::endl;}
OUTPUT:
7 --> 79
10 --> 199
7 --> 7
"""
-
Three back-ticks, not three double quotes.
Double quote:"
Back-tick:`
-
@hustbaer sagte in PROBLEM WITH INTEGER SUM:
Three back-ticks, not three double quotes.
Double quote:"
Back-tick:`
This person/individual wants to "bullshit you", and no one notices. As an excuse comes: I'm a newbie or my cat ran over the keyboard...
-
Thanks cough bear. I have noted your comments.
-
@EinNutzer0 sagte in PROBLEM WITH INTEGER SUM:
This person/individual wants to "bullshit you", and no one notices. As an excuse comes: I'm a newbie or my cat ran over the keyboard...
Du merkst vielleicht, dass hier (und in seinem anderen Thread) keine ernsthaften Antworten kommen, sondern jeder nur amüsiert dem Zugunglück zusieht. Auch wir anderen merken, wenn wir verarscht werden
-
@SeppJ sagte in PROBLEM WITH INTEGER SUM:
. Auch wir anderen merken, wenn wir verarscht werden
Spätestens bei 'cough bear' ...
-
Modified code as below.
#include <iostream> class Test { public: static int solve(int N) { int sum1 = 0; while (N != 0) { sum1 += N % 10; N /= 10; } return sum1; } static void smallestnum(int N) { std::cout << (N % 9 + 1) * pow(10, (N / 9)) - 1; } }; int main() { int N = 16; Test::smallestnum(N); return 0; }
-
@bugsfinder2022 Are you usually using java? Thank God, we do not have to put our free-functions in stupid and useless classes!
-
Das ist übrigens A051885, falls sich ein Leser wundert, was die Aufgabe soll.
-
@bugsfinder2022 If all "functions" in a class are static-defined, there is no need for such a class, especially if it contains no more than two functions.
Moreover, the class does not contain any attributes at all...
-
Yes, I agree that we dont need classes nor static members here.