Reasoning:
Let's denote the size of a large server as L and the size of a smaller server as S.
According to the data provided, we have two equations:
2L + 4S = 64.............(1)
and
L + 3S = 40...............(2)
To solve the equations, we proceed as follows:
2(2)-(1)
2L - 2L + 6S - 4S = 2*40 - 64
2S = 16
thus, S = 8..................(3), which indicates the size of the small server
Using (3) in (2) yields
L + 3(8) = 40
L = 40 - 24 = 16..............indicating the size of the large server
public static int factorial(int n) {
if (n >= 1 && n <=12) {
if (n == 1)
return 1;
else
return n * factorial(n - 1);
}
else
return -1;
}
Explanation: The factorial method takes a single integer n as input. It checks if n is within the range of 1 to 12. If it is, it further checks if n equals 1. If it is indeed 1, it returns 1 as the factorial. Otherwise, it recursively calls itself with n decreased by 1, multiplying the result by n. If n is outside this range, the method returns -1 indicating the input is invalid.
int currentNumber,previousNumber = -1, countDuplicates = 0;
do {
cin >> currentNumber;
if ( previousNumber == -1) {
previousNumber = currentNumber;
}else {
if ( previousNumber == currentNumber )
countDuplicates++;
else
previousNumber = currentNumber;
}
} while(currentNumber > 0 );
cout << countDuplicates;