WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V
1.)INITIALIZE THE VECTOR, V, WITH 10 INTEGERS WITH VALUES FROM 1 TO 10
2.)OUTPUT THE VECTOR IN DESCENDING ORDER, THEN ASCENDING ORDER
2.)ADD ALL THE EVEN NUMBERS
3.)ADD ALL THE ODD NUMBERS
4.)OUTPUT THE SUM OF EVEN INTEGERS
5.)OUTPUT THE SUM OF ODD INTEGERS
7.)OUTPUT THE PRODUCT OF EVEN INTEGERS
8.)OUTPUT THE PRODUCT OF ODD INTEGERS
SAMPLE:
Vector:
2 4 3 5 2 3 8 9 1 10
Ascending Order: 1 2 2 3 3 4 5 8 9 10
Descending order: 10 9 8 5 4 3 3 2 2 1
Even Sum: 2 + 4 + 2 + 8 + 10 = 26
Odd Sum: 3 + 5 + 3 + 9 + 1 = 21
Even PRODUCT: 2 * 4 * 2 * 8 * 10 = 1280
Odd PRODUCT: 3 * 5 * 3 * 9 * 1 = 405
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v{2 ,4 ,3 ,5 ,2 ,3 ,8 ,9 ,1 ,10};
// v.push_back(2);
// v.push_back(4);
// v.push_back(3);
// v.push_back(5);
// v.push_back(2);
// v.push_back(3);
// v.push_back(8);
// v.push_back(9);
// v.push_back(1);
// v.push_back(10);
sort(v.begin(), v.end());
cout << "Ascending \n";
for (auto x : v)
cout << x << " ";
cout<<endl;
sort(v.begin(), v.end(), greater<int>());
cout << "Descending \n";
for (auto x : v)
cout << x << " ";
cout<<endl;
int even=0;
for(int i=0;i<v.size();i++){
if(v[i]%2==0){
even+=v[i];
}
}
cout<<"even sum"<<even<<endl;
int odd=0;
for(int i=0;i<v.size();i++){
if(v[i]%2!=0){
odd+=v[i];
}
}
cout<<"odd sum"<<odd<<endl;
int evenprod=1;
int oddprod=1;
for(int i=0;i<v.size();i++){
if(v[i]%2!=0){
oddprod*=v[i];
}
if(v[i]%2==0){
evenprod=evenprod*v[i];
}
}
cout<<"even product "<<evenprod<<endl;
cout<<"odd product "<<oddprod <<endl;
return 0;
}
WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH...
In C language
1. Write a program to declare and initialize an array of size 5 and place odd numbers 3, 5, 7,9 and 11 in it. Declare and initialize another array of size 5 and place even numbers 4, 6, 8, 10 and 12 in it. Write a for loop to add each element and place it in a third array of the same dimensions. Display each array.
Write code that declares an array of integer values that will represent the first five even numbers: 2, 4, 6, 8, 10. Add code to initialize each element of the array with the even number values shown above. Add code to calculate the product of the array elements, and store the result in a variable named product. You must access the array elements to accomplish this. Do not write product = 2 * 4 * 6 * 8 * 10;...
Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...
Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...
Develop c program and give me screenshot of output? Develop a program that accepts integers from command line and uses fork() to have 4 child processes that will do sorting the integers into ascending order, computing the sum of the integers, and counting the number .of even numbers and the number of odd numbers respectively.
Develop c program and give me screenshot of output? Develop a program that accepts integers from command line and uses fork() to have 4 child processes that will do sorting the integers into ascending order, computing the sum of the integers, and counting the number .of even numbers and the number of odd numbers respectively
in c++
Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...
solve c programing language with Output screeshort? Develop a program that accepts integers from command line and uses fork() to have 4 child processes that will do sorting the integers into ascending order, computing the sum of the integers, and counting the number of even numbers and the number of odd numbers respectively.
Write C program to take four integer inputs from user (A, B, C, D) then, your program should return the sum of even numbers (if there any even numbers) and the multiplication of the odd numbers (if there any odd numbers). For example: if A=1, B=2, C=3, D=4, your program will return: sum=6, multiplication=3. if A=6, B=2, C=8, D=4, your program will return: sum=20, multiplication=0. if A=1, B=3, C=5, D=4, your program will return: sum=4, multiplication=15.
Write a C program with a filename netID_intarray.c that has 2 arrays. One is a two-dimensional array of strings which contains 5 words, each word can be a max of 20 characters long. The list of strings should be static in your code. The second integer array is populated by prompting the user for 10 integers to be stored in the array. Here is the simple output: $ ./run Number Work Enter integer 1 for the array: 45 Enter integer...