wie kann ich den Code in der Konsole ausgeben?

wenn ich Console.WriteLine() nach unten schreibe damit if Funktion als erstes ausgeführt wird zeigt mir das Programm ein Fehler an wie muss ich es umschreiben damit der Code mir sagt das 111 eine Schnapszahl ist?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
CarinaSchoppe
1 year ago

Console.WriteLine(similar digits(ZAHLEINTRAGEN));

CarinaSchoppe
1 year ago
Reply to  AkiraUshia
static bool IsSchnapszahl(int number) { int digitSum = 0; // Solange die Summe der Ziffern nicht gleich der Zahl ist, weiter prüfen while (digitSum != number) { // Berechne die Summe der Ziffern digitSum = 0; int temp = number; while (temp > 0) { digitSum += temp % 10; temp /= 10; } // Wenn die Summe der Ziffern gleich der Zahl ist, handelt es sich um eine Schnapszahl if (digitSum == number) { return true; } // Andernfalls erhöhe die Zahl um 1 und prüfe erneut number++; } // Die Schleife ist beendet, weil wir eine Schnapszahl gefunden haben return true; }

This function takes a number as a parameter and uses a While loop to check whether the number is a schnapps number. Within the loop, the sum of the numbers of the current number is calculated by using the Modulo operator to isolate the number at each point, and then the integer division is used to reach the point of the next digit.

If the sum of numbers is equal to the number, the function returns true and ends the loop. Otherwise, the number is increased by 1 and the loop