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.
#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;
}
Comments
Leave a comment