Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

write a c program to find the number of even numbers that are repeating in an array,e.g,input={8,8,4,4,2,5,5},output=2,because here only 8 and 4 are repeating which are even so answer is 2

OpenStudy (anonymous):

input1:{1,2,2,4,3,4}-{key,value,key....} input2:6(array size) input3:4(value) output:2,3( print all the keys for which the value is given in input3) BR1: if the input3 is not in input1 store op=-1 BR2: if input2<0 op=-3 BR3:if any element in input1<0 op=-2

OpenStudy (turingtest):

I would think of doing something like a double "for" loop through the array. The first iteration through the loop would check to see if a given number was even (think % operator). Once the first even number is found, its index is stored in some variable, and value in another. We then continue through the loop, comparing each subsequent element in the array with the first even number, and if we are equal, we increment a counter that keeps track of how many repeating even numbers we have found, change the second occurrence of the number to 1 (so as not to trigger it as even when passing through the loop again), then continue through the loop, changing each subsequent occurrence of that number to 1. We then go repeat the process, but each time starting with one *past* the index stored from earlier, so as not to count the same number twice. when we make a pass though the array without finding a pair of numbers we return the counter.

OpenStudy (turingtest):

possible pseudocode: //initialize int variables for a value, an index, and a counter //while we have not yet reached the end of the array //iterate through the loop starting at the stored index //if the current entry is even //update the value variable to that number //update the starting index to that index //check each subsequent entry for being stored value, and if found //increment counter by one //change current entry to 1 (or any odd number) //while index has not exceeded array size //if the current entry is the same as the stored value //change that entry to 1 (or any odd number) //else if we have reached the end of the array //return counter

OpenStudy (turingtest):

example flow of control" count = 0 value = 1 index = 0 array starting at index: [5, 6, 3, 2, 1, 2, 4, 6, 2] (for loop executes) value = 6 index = 2 (loop continues) count++ array[7] = 1 array starting at index: [3, 2, 1, 2, 4, 1, 2] (for loop) value = 2 index = 4 (loop continues) count++ array[5] = 1 array[8] = 1 array starting at index: [1, 1, 4, 1, 1] (for loop) value = 4 index = 7 (loop continues) end of array is reached without match since 4 is not found again, the function returns count, which at this point is 2, as we expect, since only 2 and 6 repeat

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!