[klick] für LÖSUNG:
// declare variables:
double x, y, z;
/* CHECK VARIABLES: */
// test the three inputs against each other, if all three
// are different from another, the IF branch is executed:
if ((x != z) && (x != y) && (y != z)) {
// output the "TOLL" message
Console.Write("\n 3 verschiedene Werte!"); }
// if two of the input numbers are identical, the ELSE branch is executed:
else
Console.Write("\n mind. 2 gleiche Werte!");
double a, b, c, swap;
/* CHECK VRIABLES: */
if (a < b) { // test a - b , if a is smaller -> swap
swap = a;
a = b;
b = swap; }
if (a < c) { // test a - c , if a is smaller -> swap
swap = a;
a = c;
c = swap; } // a now guaranteed to be the biggest number
if (b < c) { // test b - c , if b is smaller -> swap
swap = b;
b = c;
c = swap; } // c now guaranteed to be the smallest value
/* OUTPUT: */
Console.Write($"\n größter Wert: {a} " +
$"\n mittlerer Wert: {b}" +
$"\n kleinster Wert: {c}");
int days, month;
switch (month)
{
case 1: // Jänner
case 3: // März
case 5: // Mai
case 7: // Juli
case 8: // August
case 10: // Oktober
case 12: // Dezember
days = 31;
break;
case 4: // April
case 6: // Juni
case 9: // September
case 11: // November
days = 30;
break;
case 2: // Februar
days = 28;
break;
default: // invalid input
days = -1;
break;
}
if (days == -1)
{
Console.Write("\n ungültige Eingabe! ");
}
else
Console.WriteLine($"\n Der {month}. Monat hat {days}Tage. ");
}
a = a * b + 2 * c;
int i, j;
/* LOOP A: */
i = 1; j = 1; /// start values
do
{
i = i + j;
j++;
Console.Write($"\n i={i} & j={j} ");
} while (i < 200);
Console.Write("\n A terminierte");
/* LOOP B: */
i = 1; j = 20; /// start values
while (i + j < 100)
{
i = i + 2;
j--;
Console.Write($"\n i:{i} & j:{j} --> i+j:{i+j}");
}
Console.Write("\n B terminierte");
int n, i = 1;
/* CALCULATION: */
while (n / 10 != 0)
{
i++;
n = n / 10;
}
/* OUTPUT: */
Console.Write($"\n Die Zahl hatte: {i}Stellen. ");
[klick] für LÖSUNGSVORSCHLAG:
Das Einlesen und Ausgeben mit "Console.Write ... " von Variablen,
kann beim Test ausgesparrt werden!