Ask Question
20 January, 21:00

Given an int variable k, an int array incompletes that has been declared and initialized, an int variable nIncompletes that contains the number of elements in the array, an int variable studentID that has been initialized, and an int variable numberOfIncompletes, Write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes. You may use only k, incompletes, nIncompletes, studentID, and numberOfIncompletes.

+3
Answers (1)
  1. 20 January, 21:27
    0
    I will code in jа vascript.

    Preconditions:

    The variables k, incompletes has been declared and initialized.

    The variable nIncompletes contains the number of elements of incompletes.

    The variable stududentID has been declared and initialized.

    The variable numberOfIncompletes has been declared.

    Script:

    numberOfIncompletes = 0; / /initialize numberOfIncompletes

    for (k = 0; k < nIncompletes; k++) {

    if (incompletes[k] = = studentID) { / /if the element of array is equal to studentID

    numberOfIncompletes++; / /adds 1 to numberOfIncompletes

    }

    }

    Explanation:

    The script uses a for loop to go through the entire array incompletes, comparing the k variable with nIncompletes and adding 1 on each pass.

    Then inside the for, uses an if statement to compare if the actual element is equal to studentID, if equal adds 1 numberOfIncompletes.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given an int variable k, an int array incompletes that has been declared and initialized, an int variable nIncompletes that contains the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers