Function Series of input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Function Series of input

Write a C++ program to take series of numbers as input and give output 1 if even and 0 if odd using functions

4th Jul 2021, 5:42 AM
Viraj
Viraj - avatar
7 Answers
+ 3
not right order in first loop parenthesis: for (int i=0; i++; i<size) must be: for (int i=0; i<size; i++) not correct operator used in check function: if (arr[i] / 2==0) must be: if (arr[i] % 2==0)
4th Jul 2021, 5:46 AM
visph
visph - avatar
+ 2
visph sure !! 😅😅🤝
4th Jul 2021, 2:22 PM
Viraj
Viraj - avatar
+ 1
#include <iostream> using namespace std; void check (int[],int ); int main() { int size; cout<<" how many numbers you want to enter ? "; cin>>size ; int arr[size]; for(int i=0;i++;i<size) { cin>>arr[i]; } check (arr,size); } void check (int arr[],int size) { for(int i =0;i <size; i++) if (arr[i] / 2==0) { cout<<" 1 "<<endl; } else { cout<<" 0 "<< endl; } } This was my attempt but it didn't work
4th Jul 2021, 5:42 AM
Viraj
Viraj - avatar
+ 1
Thanks
4th Jul 2021, 9:59 AM
Viraj
Viraj - avatar
+ 1
Finally 😌 #include <iostream> using namespace std; void check (int[],int ); int main() { int size; int arr[size]; cout<<" how many numbers you want to enter ? "; cin>>size; cout<<"Enter numbers"<<endl; for(int i=0;i<size;i++) { cin>>arr[i]; } check (arr,size); return 0; } void check (int arr[],int size) { for(int i =0;i <size; i++) if (arr[i] % 2==0) { cout<<" 1 "<<endl; } else { cout<<" 0 "<< endl; } }
4th Jul 2021, 10:05 AM
Viraj
Viraj - avatar
+ 1
Guru patel don't mark your own answer as best: it's not true and it's unfair (I give you the corrections to be done) and it will not give you any xp ^^
4th Jul 2021, 2:19 PM
visph
visph - avatar
- 2
2==0
6th Jul 2021, 5:16 AM
Someshwar Chanda