Answer:
The program in C++ is as follows:
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cout<<"Elements: ";
cin>>n;
vector <int>num;
int input;
for (int i = 1; i <= n; i++){ cin>>input; num.push_back(input); }
int large, seclarge;
large = num.at(0); seclarge = num.at(1);
if(num.at(0)<num.at(1)){ large = num.at(1); seclarge = num.at(0); }
for (int i = 2; i< n ; i ++) {
if (num.at(i) > large) {
seclarge = large;;
large = num.at(i);
}
else if (num.at(i) > seclarge && num.at(i) != large) {
seclarge = num.at(i);
}
}
cout<<"Second Largest: "<<seclarge<<endl;
int small, secsmall;
small = num.at(1); secsmall = num.at(0);
if(num.at(0)<num.at(1)){ small = num.at(0); secsmall = num.at(1); }
for(int i=0; i<n; i++) {
if(small>num.at(i)) {
secsmall = small;
small = num.at(i);
}
else if(num.at(i) < secsmall){
secsmall = num.at(i);
}
}
cout<<"Second Smallest: "<<secsmall;
return 0;
}
Explanation:
See attachment for explanation
A pharmaceutical company is going to issue new ID codes to its employees. Each code will have three letters followed by one digit. The letters and and the digits , , , and will not be used. So, there are letters and digits that will be used. Assume that the letters can be repeated. How many employee ID codes can be generated
Answer:
82,944 = total possible ID's
Explanation:
In order to find the total number of combinations possible we need to multiply the possible choices of each value in the ID with the possible choices of the other values. Since the ID has 3 letters and 1 digit, and each letter has 24 possible choices while the digit has 6 possible values then we would need to make the following calculation...
24 * 24 * 24 * 6 = total possible ID's
82,944 = total possible ID's
Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lower even number.
if(n % 2 == 0){
for(int i = n; i >= 0; i-=2){
System.out.println(i);
}
}
else{
for(int i = n - 1; i >= 0; i-=2){
System.out.println(i);
}
}
Sample output
Output when n = 12
12
10
8
6
4
2
0
Output when n = 21
20
18
16
14
12
10
8
6
4
2
0
Explanation:The above code is written in Java.
The if block checks if n is even by finding the modulus/remainder of n with 2. If the remainder is 0, then n is even. If n is even, then the for loop starts at i = n. At each cycle of the loop, the value of i is reduced by 2 and the value is outputted to the console.
If n is odd, then the else block is executed. In this case, the for loop starts at i = n - 1 which is the next lower even number. At each cycle of the loop, the value of i is reduced by 2 and the value is outputted to the console.
Sample outputs for given values of n have been provided above.