Answer to Question #271297 in C++ for Immanuel

Question #271297

1. Write a program that accepts 10 integers saves them in an array, seperates the even. Integers from the odd ones by saving them in seperate arrays, and prints the even one on the first line followed by the odd ones on the second line.

Sample Run:

Enter 10 integers: 1 2 3 4 5 6 7 8 9 10

2 4 6 8 10

1 3 5 7 9


2. Write a program that accepts up to 10 grades (double) and determines the highest grade and their average.A

Sample Run

Enter 10 grades: 78 79 80 81 82 83 67 66 65 90

The highest is 90.

The average is 77.10!


3. Write a program that accepts 10 integers, saves them in an arrays, and prints the sums of even integers and odd integers

Sample Run:

Enter 10 integers: 1 2 3 4 5 6 7 8 9 10

Sum of even: 30

Sum of odd: 25


1
Expert's answer
2021-11-25T07:04:39-0500
#include<iostream>
using namespace std;
int main(){
	int arr[10];
	int even[5], odd[5], e=0, o=0;
	cout<<"Enter 10 integers: ";
	for(int i=0; i<10; i++){
		cin>>arr[i];
		if(arr[i]%2==0){
			even[e]=arr[i];
			e++;
		}
		else{
			odd[o] = arr[i];
			o++;
		}
	}
	
	for(int i=0; i<5; i++){
		cout<<even[i]<"  ";
	}
	cout<<endl;
	for(int i=0; i<5; i++){
		cout<<odd[i]<"  ";
	}
}





#include <iostream>

using namespace std;

sample_run_one(int number[12]) {
int even[12], odd[12], even_cnt = 0, odd_cnt = 0;
for(int i = 0; i < 10; i++) {
if(number[i] % 2 == 0) {
even[even_cnt] = number[i];
even_cnt++;
}
else {
odd[odd_cnt] = number[i];
odd_cnt++;
}
}
for(int i = 0; i < even_cnt; i++) {
cout<<even[i]<<" ";
}
cout<<endl;
for(int i = 0; i < odd_cnt; i++) {
cout<<odd[i]<<" ";
}
cout<<endl;
}

sample_run_two(int number[12]) {
int max = 0;
float sum;
for(int i = 0; i < 10; i++) {
if(number[i] > max) max = number[i];
sum += number[i];
}
cout<<"The highest is "<<max<<endl;
cout<<"The average is "<<sum/10<<endl;
}

sample_run_three(int number[12]) {
int even_sum = 0, odd_sum = 0;
for(int i = 0; i < 10; i++) {
if(number[i] % 2 == 0) even_sum += number[i];
else odd_sum += number[i];
}
cout<<"Sum of even: "<<even_sum<<endl;
cout<<"Sum of odd: "<<odd_sum<<endl;
}

main() {
int num_input[12], run_cnt;
while(true) {
cout<<"Enter sample run number and press Enter key!!!"<<endl;
cin>>run_cnt;
if(run_cnt == 1) cout<<"Enter 10 integers"<<endl;
else if(run_cnt == 2) cout<<"Enter 10 grades"<<endl;
else if(run_cnt == 3) cout<<"Enter 10 integers"<<endl;
else cout<<"There is no corresponding run number"<<endl;
for(int i = 0; i < 10; i++)
cin>>num_input[i];
if(run_cnt == 1) sample_run_one(num_input);  //Sample Run 1
if(run_cnt == 2) sample_run_two(num_input);  //Sample Run 2
if(run_cnt == 3) sample_run_three(num_input);  //Sample Run 3
cout<<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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS