#include <iostream>
using namespace std;
int main()
{
}
Write a program that solicits a user-specified amount of numbers and their values, and then computes the average value, as well as their parity (how many even versus odd).
Below is the console content of an example run of the completed program.
How many numbers would you like to store? 8
Enter the 8 numbers: 0 7 3 1 5 6 2 3
Average value: 3.125
Parities: 3 even, 5 odd
#include <iostream>
using namespace std;
int main()
{
// Ask user to enter number to score
int num;
cout<<"How many numbers would you like to store? ";
cin>>num;
// Declare array of num size
int arr[num];
// Take input
cout<<"Enter the "<<num<<" numbers: ";
for(int i =0 ;i<num;i++){
cin>>arr[i];
}
double avg = 0;
int even = 0;
int odd = 0;
// Iterate loop over array
// Calculate average, odd and even
// If number is divisible by 2, its even else odd
for(int i = 0;i<num;i++){
avg+=arr[i];
if(arr[i]%2==0){
even+=1;
}else{
odd+=1;
}
}
avg/=num;
// Print result
cout<<"Average value: "<<avg<<endl;
cout<<"Parities: "<<even<<" even,
"<<odd<<" odd"<<endl;
return 0;
}
OUTPUT-

#include <iostream> using namespace std; int main() { } Write a program that solicits a user-specified...
#include <iostream> using namespace std; int main() { } Write a program that, given a user-specified integer, prints out the next 10 integers (in increasing order; each on its own line). For example, given an input of 3, the console content following a run of the completed program will look as follows: Enter a number: 3 4 5 6 7 8 9 10 11 12 13
#include <iostream> using namespace std; int main() {} Write a program that produces a line comprised of n alternating a's and b's, where n is user-specified. For example, the console content following a run of the completed program with an input of "5" is as follows: Enter a number: 5 A line of length 5: ababa
#include <iostream> using namespace std; int main () { } Write a program that converts a numeric score (provided by the user) into a letter grade (A, B, C, D, or F). The point-to-letter conversion rules are as follows: score >= 90: A score >= 80 (but less than 90): B score >= 70 (but less than 80): C score >= 60 (but less than 70): D otherwise: F The completed program should produce console content as follows: Enter your...
#include <iostream> using namespace std; int main() { int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int upperbound; // Sum from 1 to this upperbound // Prompt user for an upperbound cout << "Enter the upperbound: "; cin >> upperbound; // Use a loop to repeatedly add 1, 2, 3,..., up to upperbound int number =...
#include <iostream> using namespace std; void drawTriangle(int w) {} int main() {} Complete the program so that it produces a centered, isosceles triangle of a user-specified width. For example: Enter a width: 5 Result: ***** *** *
#include <iostream> using namespace std; void drawTriangle(int x) {} int main() {} Complete the program so that it produces a right-angle triangle of a user-specified height. For example: Enter a height for the triangle: 5 Result: * ** *** **** *****
#include <iostream> using namespace std; void drawRect(int h, int w) {} int main() {} Write a program that produces h x w rectangles comprised of alternating columns of 1's and 0's (where h and w all user-specified). For example: Enter the desired dimensions for a rectangle: 6 4 Result: 1010 1010 1010 1010 1010 1010
Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: "; cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2; return 0; }
Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;
Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n =0; int i = 0; cout << "Please enter a strictly positive number:"; cin >> n if (n <= 0) exit(EXIT_FAILURE) while (n > 1) n-n/2; i << endl; cout"Output:" return 0; Answer the following questions: What is the output of the program for each of the following values of n: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9? What does...