by Jan Ritt - 3ACIF [ 71% - 3 ]
Vollständige pdf
Vollständige pdf
Vollständige pdf
Vollständige Solution
[klick] - Nummer 1:
/* DECLARE VARIABLES */
double x,y, z;
/* CALCULATION ------------------------ // TEST ARGUMENTS */
if ((x == y && x != z) || // x IS y AND NOT z OR ..
(x == z && x != y) || // x IS z AND NOT y OR ..
(y == z && y != x)) // y IS z AND NOT x
{ // if ONE ARGUEMENT is TRUE
/* OUT */ Console.Write("\n Genau 2 Werte sind gleich.");
}
else
{ // if ALL ARGUMENTS are FALSE
/* OUT */ Console.Write("\n Es sind nicht genau 2 Werte gleich.");
}
[klick] - Nummer 2:
/* DECLARE VARIABLES */
double a, b, c,
swap;
/* CALCULATION */
if (a < b) // SWAP a & b IF b is bigger
{ swap = a;
a = b;
b = swap;
}
if (a < c) // SWAP a & c IF c is bigger
{ swap = a;
a = c;
c = swap;
}
if (b < c) // SWAP b & c IF c is bigger
{ swap = b;
b = c;
c = swap;
}
/* OUT */ Console.Write($"\n Absteigende Reihenfolge:" +
$"\n {a}" +
$"\n {b}" +
$"\n {c}");
[klick] - Nummer 3:
/* DECLARE VARIABLES */
int month, days;
/* CALCULATION */
switch (month)
{ case 1: // January
case 3: // March
case 5: // May
case 7: // July
case 8: // August
case 10: // October
case 12: // December
days = 31;
break;
case 4: // April
case 6: // June
case 9: // September
case 11: // November
days = 30;
break;
case 2: // February
days = 28; // Assuming no leap year for simplicity
break;
default:
Console.Write("\nAbbruch\n");
return;
}
/* OUT */ Console.Write($"\n Der {month}. Monat hat {days} Tage.");
[klick] - Nummer 4:
/* DECLARE VARIABLES */
int x, y, a,
shortA;
/* CALCULATION ------ original code ------------ */
if (x < 0 && y < 0) //
a = x * y; //
else if (x < 0) //
a = x * (-y); // -------- x --------
else if (y > 0) // -1 | -1 | 1 | 1
a = (-x) * (-y); //
else // -------- y --------
a = x * (-y); // -1 | 1 | -1 | 1
/* CALCULATION ------ shortened code ----------- */
shortA = (x * y < 0) ? x * (-y) : x * y;
/* OUT */ Console.Write($"\n [a]: {a}" + // a 1 | 1 | 1 | 1
$"\n [A]: {shortA}"); // A 1 | 1 | 1 | 1
[klick] - Nummer 5:
/* DECLARE VARIABLES */
int y, x, j;
/* LOOP A */ y = 1; j = 1;
do
{ y = y + j;
j--;
/* A */ } while (y < 200);
/* NOT TERMINATED */
/* LOOP B */ x = 1; j = 20;
while (x+j < 100)
{ x = x + 3;
j--; j--;
/* B - TERMINATED */}
[klick] - Nummer 6:
/* DECLARE VARIABLES */
int n, sum;
sum = 0;
/* CALCULATION */
while(n != 0)
{ sum = sum + (n % 10);
n = n / 10;
}
/* OUT */ Console.Write($"\n Die Ziffernsumme der Zahl ist {sum}");