Q: Write a c++ program that will count the number of even,odd and zero's.
#include<iostream> using namespace std; int main() { int n; cout<<"how many numbers : ";cin>>n; int num; int even=0,odd=0,zero=0; cout<<"\n\n"; for(int i=0;i<n;i++) { cout<<"Enter "<<i+1<<" "<<"number : "; cin>>num; switch(num%2) { case 0: if(num==0) zero++; even++; break; case 1: odd++; break; default: cout<<"Not a positive integer.\n"; break; } } cout<<" \n\t\tEVEN NUMBERS ARE :\t"<<even; cout<<" \n\t\tODD NUMBERS ARE :\t"<<odd; cout<<" \n\t\tZERO'S ARE :\t"<<zero; cout<<"\n\n\n"; system("pause"); return 0; }
0 comments:
Post a Comment