Array Sum & Count Odd Numbers C Plus Plus

By | July 11, 2019

Task: Array Sum & Count Odd Numbers C Plus Plus Program

Array Sum & Count Odd Numbers C Plus Plus Program

Array Sum & Count Odd Numbers C Plus Plus Program

The Source Code of Array Sum & Count Odd Numbers C Plus Plus

// Write a C++ program to input 10 numbers
// in array then display only odd numbers, their
// sum and count in array
// Author: www.EasyCodeBook.com (c)
#include<iostream>

using namespace std;
int main()
{
	int arr[10],i,sum,count;
	for(i=0;i<10;i++)
	{
		cout<<"Enter Number "<<(i+1)<<"  :";
		cin>>arr[i];
	}
	sum=count=0;
	cout<<"Odd numbers in Array are:"<<endl;
	for (i=0;i<10;i++)
	  if(arr[i]%2==1)
	  {
	  	cout<<arr[i]<<", ";
	  	count++;
	  	sum=sum+arr[i];
      }
	cout<<"\nCount of Odd numbers is: "<<count<<endl;
	cout<<"Sum of Odd numbers is: "<<sum<<endl;
	
	return 0;
}

Output of a Sample Run of C++ Array Program

Enter Number 1  :1
Enter Number 2  :2
Enter Number 3  :3
Enter Number 4  :4
Enter Number 5  :5
Enter Number 6  :6
Enter Number 7  :7
Enter Number 8  :8
Enter Number 9  :9
Enter Number 10  :100
Odd numbers in Array are:
1, 3, 5, 7, 9,
Count of Odd numbers is: 5
Sum of Odd numbers is: 25

--------------------------------
Process exited after 219.8 seconds with return value 0
Press any key to continue . . .

You may also like C++ Program to find sum and count of even numbers in Array

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *