The program must accept an array of N even integers as the input. The program must print the output based on the following conditions.
– For each integer in the array, the program must divide the integer by 2. Then the program must print the integers in the revised array. Then the program must remove all the odd integers in the revised array(if present).
– Then the program must repeat the above process on the revised array till the size of the array becomes 0.
Boundary Condition(s):
1 <= N <= 100
2 <= Each integer value <= 10^8
Input Format:
The first line contains N.
The second line contains N integers separated by a space.
Output Format:
The lines contain the integer values separated by a space based on the given conditions.
Example Input/Output 1:
Input:
4
32 60 8 200
Output:
16 30 4 100
8 15 2 50
4 1 25
2
1
Explanation:
Here N = 4, and the four even integers are 32, 60, 8 and 200.
[32, 60, 8, 200] -> [16, 30, 4, 100] (No odd integers obtained).
[16, 30, 4, 100] -> [8, 15, 2, 50] (15 is the only odd integer to be removed).
[8, 2, 50] -> [4, 1, 25] (1 and 25 are the two odd integers to be removed).
[4] -> [2] (No odd integers obtained).
[2] -> [1] (1 is the only odd integer to be removed).
[] -> Now the size of array becomes 0.
Example Input/Output 2:
Input:
5
90 40 80 52 64
Output:
45 20 40 26 32
10 20 13 16
5 10 8
5 4
2
1
n = int(input())
a = list(map(int,input().split()))
while len(a) > 0:
a = [i//2 for i in a]
print(*a)
a = [i for i in a if i%2 == 0]
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,count=0;
scanf("%d",&n);
int arr[n];
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(int i=0;i<100;i++)
{
count=0;
for(int j=0;j<n;j++)
{
if((arr[j]%2)==0)
{
printf("%d ",arr[j]/2);
arr[j]=arr[j]/2;
count++;
}
}
if(count==0)
{
break;
}
printf("n");
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int c=0;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int j=0;
int size=n;
while(size!=0)
{
for(int i=0;i<n;i++)
{
arr[i]=arr[i]/2;
if(arr[i]!=0)
cout<<arr[i]<<" ";
}
cout<<endl;
for(int i=0;i<n;i++)
{
if(arr[i]%2==1)
{
arr[i]=0;
size--;
}
}
}
}
import java.util.*;
public class Hello {
static boolean isOnes(List<Integer> list) {
int temp = 0;
for(int i: list) {
if(i == 1) continue;
else temp = 1;
}
if(temp == 0) return true;
return false;
}
static void print(List<Integer> list) {
for(int i: list) System.out.print(i + " ");
System.out.println();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
List<Integer> temp = new ArrayList<Integer>();
for(int i = 0; i < n; i++) list.add(sc.nextInt());
while(list.size() > 0) {
for(int i = 0; i < list.size(); i++)
list.set(i, list.get(i) / 2);
print(list);
if(isOnes(list)) break;
for(int i = 0; i < list.size(); i++) {
if(list.get(i) % 2 == 0)
temp.add(list.get(i));
}
list = new ArrayList<>(temp);
temp.clear();
}
}
}