Consider this C program, C++ Program, Java program or C# Program. It reads integers from the standard input (until it gets a negetive number) and puts them into an array. After that it calls processArray on the array, and then prints the contents of the array on standard output.
For this question, we define a black number as any number that is divisible by 7, and a white number that is divisible by 8.
Currently, processArray does not modify the array. You have to change this program so that any number in the array is replaced by -2 if it is a blck number, with -9 if it is a white number, and with -6 if it is both a black and white number. To do this, you have to put your code inside processArray. Do not change anything else in the program.
For example, if these numbers were provided on the standard input:
84
13
96
56
-1
Then the program should print:
-2
13
-9
-6
Solution in Python
arr=[]
while True:
x=int(input())
if x==-1:
break
else:
arr.append(x)
#Solved by codewindow.in
for i in range(len(arr)):
if arr[i]%7==0 and arr[i]%8==0:
arr[i]=-6
elif arr[i]%8==0:
arr[i]=-9
elif arr[i]%7==0 :
arr[i]=-2
for i in arr:
print(i)