+ 1

I want to write a presentation that takes 100 numbers and prints even and odd separately. If the input is not zero,

This code will not run #include<iostream> using namespace std; int main() { int arr[100]; for (int i=0;i<100;i++) { cin>>arr[i]; char p; p=cin.get() !=0; if(arr[i]%2==0) { cout<<i << '/t'; } } return 0; }

7th May 2022, 6:30 AM
Mhdis
Mhdis - avatar
6 Respuestas
+ 3
Do you mean to print odd and even numbers on separate lines, or to print count of even and odd numbers on separate lines? Your last paragraph was broken ... "If the input is not zero," Then what?
7th May 2022, 6:42 AM
Ipang
+ 3
Mhi tj "Input is not zero" means inputs between 1 to 100? You can simply skip if input is 0 like this: if (arr[i] == 0) continue; And also there is \t not /t Also you have to print arr[i] not i
7th May 2022, 8:09 AM
A͢J
A͢J - avatar
+ 1
Yesss
7th May 2022, 6:52 AM
Mhdis
Mhdis - avatar
+ 1
Please write it
7th May 2022, 6:52 AM
Mhdis
Mhdis - avatar
+ 1
Mhi tj I think you have to read all the 100 values first if you want to display them on separate lines. Begin with using lowest index (0) as the index for storing even values <even_index>, and the highest index (99) as the index for storing odd values <odd_index>. Increment <even_index> after storing even number, decrement <odd_index> after storing odd number. When it's time for printing, start printing even values from index 0 up to <even_index>. And start printing odd values from index 99 down to <odd_index>. If instead, you want to count even and odd values, then prepare <even_count> and <odd_count>, initialize them by zero. Increment respective counter variable inside the `if` conditional you use to verify even/odd value. You can then display the counters on separate lines after the loop finished.
7th May 2022, 11:23 AM
Ipang
0
Mhi tj you don't need an array if you are only reading a single value and printing it right away.
7th May 2022, 2:34 PM
Brian
Brian - avatar