Write c++ program that
(1) Write a program that declares a single-dimensional arrays named num.
(2) The numbers to be stored in num are 45, 86, 12, 37, 28, 113.
(3) Sum odds and evens separately.
(4) Finally, give the results that will be displayed on the screen.
(5)run test it in main
#include<iostream>
using namespace std;
int main(){
int num[6] = { 45, 86, 12, 37, 28, 113};
int even = 0;
int odd = 0;
for(int i=0; i<6; i++){
if(num[i]%2==0){
even += num[i];
}
else{
odd += num[i];
}
}
cout<<"The sum of even: "<<even<<endl;
cout<<"The sum of odd: "<<odd<<endl;
}
Comments
Leave a comment