Answer to Question #284621 in C++ for Sara

Question #284621

Write a C++ program that do the following:

• Declare an array of size 10 double.

• Ask the user to enter 10 double and store them in the array.

• Print the maximum element in the array.

• Print all odd numbers in the array.

• Count and print odd numbers in the array.


1
Expert's answer
2022-01-04T01:09:54-0500


#include <iostream>
#include <iomanip>
using namespace std;


int main() {




	//- Declare an array of size 10 double.
	double numbers[10];
	//- Ask the user to enter 10 double and store them in the array.
	for(int i=0;i<10;i++){
		cout<<"Enter the number "<<(i+1)<<": ";
		cin>>numbers[i];
	}
	//- Print the maximum element in the array.
	double maximum=numbers[0];
	int oddCounter=0;
	for(int i=0;i<10;i++){
		if(maximum<numbers[i]){
			maximum=numbers[i];
		}
	}
	cout<<maximum<<" is the maximum element in the array.\n";
	//- Print all odd numbers in the array.
	cout<<"\n\nAll odd numbers in the array:\n";
	for(int i=0;i<10;i++){
		if((int)numbers[i]%2==1){
			cout<<numbers[i]<<"\n";
			oddCounter++;
		}
	}
	//- Count and print odd numbers in the array.
	cout<<oddCounter<<" odd numbers in the array.\n";


	cin>>maximum;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog