Answer to Question #276889 in C++ for Roe

Question #276889

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

1
Expert's answer
2021-12-07T20:57:48-0500
#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;
	
}

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