Task: Sum & Count of Even Odd Separately in Array

// Write a C++ program to input 10 numbers // in array then display sum and count of even // and odd numbers in Array, separately. // Author: www.EasyCodeBook.com (c) #include<iostream> using namespace std; int main() { int arr[10],i,esum,osum,ecount,ocount; for(i=0;i<10;i++) { cout<<"Enter Number "<<(i+1)<<" :"; cin>>arr[i]; } esum=osum=ecount=ocount=0; //show even numbers, sum and count cout<<"Even numbers in Array are:"<<endl; for (i=0;i<10;i++) if(arr[i]%2==0) { cout<<arr[i]<<", "; ecount++; esum=esum+arr[i]; } cout<<"\nCount of Even numbers is: "<<ecount<<endl; cout<<"Sum of Even numbers is: "<<esum<<endl; // show even numbers, sum and count cout<<"Odd numbers in Array are:"<<endl; for (i=0;i<10;i++) if(arr[i]%2==1) { cout<<arr[i]<<", "; ocount++; osum=osum+arr[i]; } cout<<"\nCount of Odd numbers is: "<<ocount<<endl; cout<<"Sum of Odd numbers is: "<<osum<<endl; return 0; }

Enter Number 1 :10 Enter Number 2 :11 Enter Number 3 :12 Enter Number 4 :13 Enter Number 5 :1 Enter Number 6 :2 Enter Number 7 :3 Enter Number 8 :4 Enter Number 9 :5 Enter Number 10 :6 Even numbers in Array are: 10, 12, 2, 4, 6, Count of Even numbers is: 5 Sum of Even numbers is: 34 Odd numbers in Array are: 11, 13, 1, 3, 5, Count of Odd numbers is: 5 Sum of Odd numbers is: 33 -------------------------------- Process exited after 238.7 seconds with return value 0 Press any key to continue . . . You may like C++ Program to find sum / count of even numbers and to calculate sum and count of all odd numbers in Array of 10 numbers

443 total views, 1 views today

It’s amazing in support of me to have a web page, which is useful

in support of my experience. thanks admin