Given an int variable k, an int array incompletes that has been declared and initialized, an int variable n Incompletes that contains the number of elements in the array, an int variable student ID that has been initialized, and an int variable number Of Incompletes, write code that counts the number of times the value of student ID appears in incompletes and assigns this value to number Of Incompletes. You may use only k, incompletes, n Incompletes, student ID, and number Of Incompletes.

Answer :

Answer:

The answer to this question can be given as:

Code:

int k;

int incompletes[]={1,2,3,4,5,6,7,8,9};

int nIncompletes=9,studentID=9;

int numberOfIncompletes=0;

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

{

if (incompletes[k] == studentID)

{

numberOfIncompletes++;

}

}

Explanation:

In the above code firstly we declare an integer variable that k, nIncompletes, studentID, numberOfIncompletes. In variable nIncompletes and studentID we assign value also. Then we declare an array  incompletes[] in this array we initialized value. All the variable name is already given in the questions. Then we declare the for loop in the for loop we use the if conditional statement. In the if block we check the condition that is if incompletes array elements is equal to studentID then the numberOfIncompletes variable increase its value by 1.

Other Questions