Question

In: Computer Science

(20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing...

  1. (20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing on your experience from program 1, read an integer, n from keyboard (standard input). This integer represents the number of integers under consideration. After reading that initial integer in, read n integers in, and print the minimum and maximum of all the integers that are read in.

Example:

Input

Output

7

1 5 3 6 9 22 2

Min: 1

Max: 22

C++ preferred

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main()
{
//initializing n,min,max and number
int n,min,max,num;
//accepting n
cin>>n;
//accepting first number
cin>>num;
//assigning it to max
max=num;
//assigning it to min
min=num;
//looping from 0 to num-1
for(int i=0;i<n-1;i++){
//accepting number
cin>>num;
//checking if it is greater than max
if(num>max)
//assigning num to max
max=num;
//checking if it is less than min
if(num<min)
//assigning num to min
min=num;
}
//printing Min
cout<<"Min: "<<min<<endl;
//printing Max
cout<<"Max: "<<max<<endl;
return 0;
}


Screenshot:


Input and Output:


Related Solutions

Implement the MSI cache coherence protocol in your favorite programming language (C, C++, Java, python, etc.)....
Implement the MSI cache coherence protocol in your favorite programming language (C, C++, Java, python, etc.). Wikipedia has a nice high level description of the protocol. Consider only one level of cache which is a write back cache. Moreover, assume that there are 4 processing cores working on a single shared memory. To simplify, assume that you are writing the code for only one block of cache and that block can hold 4 different memory locations.
Using a programming language of your choice: 1) generate a range of wavelengths, 2) compute corresponding...
Using a programming language of your choice: 1) generate a range of wavelengths, 2) compute corresponding monochromatic blackbody intensity using a) Planck function, b) Rayleigh-Jeans simplification, and c) Wien simplification, and 3) plot the three resulting spectra (i.e., a diagram that shows how B(λ) changes with λ). Using this figure explain the phenomenon of “ultraviolet catastrophe”. Please include the code (not only figure) in your answer.
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
Java, Python, and C++ are three of the most useful programming languages to learn. Compare the...
Java, Python, and C++ are three of the most useful programming languages to learn. Compare the functionalities of all three programming languages. Why would you choose one language over another? Provide code examples demonstrating their usefulness in a real-world scenario.
Develop a MATLAB (or programming language of your choice) code to show the flow field for...
Develop a MATLAB (or programming language of your choice) code to show the flow field for lifting cylinder flow using the following specifications. Set your free-stream velocity, cylinder radius, and vortex strength in the code. There are a total of four cases for which you will run your code (or have all four in one script). You will only be changing the vortex strength for the different cases. Therefore, set ?∞ = 1 and ? = 1 for all cases....
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Using c programming language How do you put data from a text file into a 2d...
Using c programming language How do you put data from a text file into a 2d array For example a text file with names and age: john 65 sam 34 joe 35 sarah 19 jason 18 max 14 kevin 50 pam 17 bailey 38 one 2d array should have all the names from the file and one 2d array should have all the ages and both arrays should be printed out separately and be 3x3
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the...
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) − (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT