Using C( not C++ or C#) I need help in constructing this function for a specific program without the use of arrays os strings for practice . Function Reqt - getBPswrd(int nPswrd , int nSeq) that determines the most suitable key from nPswrd for a given sequence nSeq. nSeq is an 8-digit +ve integer, while nPswrd contains a maximum of 4 one-digit positive integers merged as one integer. A number from nPswrd is selected as the best key if it matches most of the digits in nSeq. Following are some desired test cases: Hypothetically - nSeq= 12134567 and nPswrd = 1234: The nPswrd are 1, 2, 3, and 4. Pswrd Count 1 2 2 1 3 1 4 1 The best pswrd is: 1 Condtion - 2 If 2 or more different pswrd have the same count, the first key listed from the leftmost will be chosen as the best key. Example 3: Hypothetically : nSeq = 14325312 and nPswrd = 143: The pswrd are 1, 4, and 3. Pswrd Count 1 2 4 1 3 2 The best key is: 1 Last Condition There are also instances where 2 or more pswrd are just the same. Example 4: Hypothetically : nSeq = 14325312 and nPswrd = 22: The keys are 2, and 2. Pswrd Count 2 2 2 2 The best pswrd is: 2 The int main of the practice problem is as follow int main () { int nSeq, nPswrd, nB; nB = -1; printf("Sequence: "); scanf("%d", &nSeq); printf("Pswrd: "); scanf("%d", &nPswrd); nB = getBPswrd(nSeq, nPswrd); if (nB != -1) { printf("Best pswrd for the sequence: %d\n", nB); } else { printf("None of the pswrd are found in the sequence!\n"); } return 0; }
Using C( not C++ or C#) I need help in constructing this function for a specific program without the use of arrays os strings for practice .
Function Reqt - getBPswrd(int nPswrd , int nSeq) that determines the most suitable key from nPswrd for a given sequence nSeq.
nSeq is an 8-digit +ve integer, while nPswrd contains a maximum of 4 one-digit positive integers merged as one integer. A number from nPswrd is selected as the best key if it matches most of the digits in nSeq.
Following are some desired test cases:
Hypothetically - nSeq= 12134567 and nPswrd = 1234:
The nPswrd are 1, 2, 3, and 4.
Pswrd | Count |
1 | 2 |
2 | 1 |
3 | 1 |
4 | 1 |
The best pswrd is: 1
Condtion - 2
If 2 or more different pswrd have the same count, the first key listed from the leftmost will be chosen as the best key.
Example 3: Hypothetically : nSeq = 14325312 and nPswrd = 143: The pswrd are 1, 4, and 3.
The best key is: 1 |
Last Condition
There are also instances where 2 or more pswrd are just the same.
Example 4: Hypothetically : nSeq = 14325312 and nPswrd = 22: The keys are 2, and 2.
The best pswrd is: 2 |
The int main of the practice problem is as follow
int main ()
{
int nSeq, nPswrd, nB;
nB = -1;
printf("Sequence: ");
scanf("%d", &nSeq);
printf("Pswrd: ");
scanf("%d", &nPswrd);
nB = getBPswrd(nSeq, nPswrd);
if (nB != -1)
{
printf("Best pswrd for the sequence: %d\n", nB);
}
else
{
printf("None of the pswrd are found in the sequence!\n");
}
return 0;
}
Step by step
Solved in 3 steps with 1 images