I am having trouble with writing this code. I am in a beginning C plus plus clas
ID: 3707526 • Letter: I
Question
I am having trouble with writing this code. I am in a beginning C plus plus class. We are studying arrays and i am using Microsoft Visual Studios. with #include<iostream>,#include<iomanip>,#include<cmath>. Thank u
. Let array A-4,10,3,9,18,22,245,27), B--1-2-3), C-100,200,300 100, 200,300 Write a program to: a. Separate array A into two arrays: Array E contains the even values and array O contains the odd values. Display all arrays in a column format. b. Find the largest element in array A. c. Finds the sum of all the values of the elements in A. d. Join arrays A, B, and C into one array D [A B C] 2. Write a program that displays the first 20 term in each sequence: {1,1,2,3,5,8, 13, 21, ) a, b. 4,-9,14,-19,24... 3. Write a program that reads a list of 12 integers into an array and displays: a. The integers backward (i.e. the last number entered is displayed first). b. The negative integers before the positive integers.Explanation / Answer
1a) #include<iostream>
#include<conio>
void main()
{
int A[9],A_even[9],A_odd[9],i,j=0,k=0;
A[9]={4,10,3,9,18,22,2}; //array initialisation
for(i=0;i<9;i++)
{
if(A[i]%2==0)
{ A_even[j]=A[i]; j++; }
else
{ A_odd[k]=A[i]; k++; }
}
for(i=0;i<j;i++)
cout<<A_even[i]<<' ';
cout<<endl;
for(i=0;i<k;i++)
cout<<A_odd[i]<<' ';
}
1b)
#include<iostream>
#include<conio>
void main()
{
int A[9]={4,10,3,9,18,22,2},large=0; //array initialisation
for(int i=0;i<9;i++)
if(large<A[i])
large=A[i];
cout<<"largest = "<<A[i];
}
1c)
#include<iostream>
#include<conio>
void main()
{
int A[9]={4,10,3,9,18,22,2},sum=0; //array initialisation
for(int i=0;i<9;i++)
sum+=A[i];
cout<<"SUM= "<<sum;
}
1d)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.