Question

C++ Ask the user how many numbers he wants to input and then find the smallest...

C++ Ask the user how many numbers he wants to input and then find the smallest of these numbers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;
int main(){
   int n, min, val;
   
   // Reading value for n
   cout<<"How many numbers you wants to input: ";
   cin>>n;
   
   if(n>0){
       // Reading n integers
      cout<<"Enter "<<n<<" numbers:\n";
      cin>>min;
      for(int i = 1;i<n;i++){
         cin>>val;
         // Updating min if val is less than current min
         if(min > val){
            min = val;
         }
      }
      // printing min value
      cout<<"Smallest of these number = "<<min<<endl;
   }
   
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ Ask the user how many numbers he wants to input and then find the smallest...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming Ask the user how many numbers they would like generated. Your program will then...

    C programming Ask the user how many numbers they would like generated. Your program will then generate that many numbers (between 0 and 1000, inclusive) into an array of the same size. Find the smallest and largest numbers in the array, printing out the values and locations of those numbers in the array. Then, find the sum and average of the numbers in the array. Finally, print out the entire array to verify. You MUST use functions where appropriate!

  • Ask a user for three positive integer numbers. Use an input validation loop to make sure...

    Ask a user for three positive integer numbers. Use an input validation loop to make sure that all numbers are positive, ask again if not. Determine the smallest, middle and largest number and display them with proper labeling (Smallest=AA, Middle=BB, Largest=CC). Write this program in C

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • Write program in C. Please ask the user to determine how many numbers to enter, and...

    Write program in C. Please ask the user to determine how many numbers to enter, and then find and display the largest one with two digits. Please call the following two functions in your main functions. void input_numbers(float *data, int num); void find_largest(float *data, int num); Note: In this assignment, please save the entered numbers using pointer, pass the pointer as the arguments. Depending upon the number of elements, the required size is allocated which prevents the wastage of memory....

  • Write a C Language Program that will ask the user how many elements the "maxminarray" will...

    Write a C Language Program that will ask the user how many elements the "maxminarray" will have. Read the elements from user and fill the "maxminarray” with it. Find maximum value and minimum value in maxminarray See the output below: Input number of elements of the array :6 Input 6 elements for the maxminarray : element [0]: 23 element [1] : 56 element [2] : 11 element [3]: 78 element [4]: 21 element [5]: 400 The Maximum element is :...

  • C++ program please. As simple as possible. 1.(40) Write a program that will find the smallest...

    C++ program please. As simple as possible. 1.(40) Write a program that will find the smallest value entered by the user and print out the entered numbers with the smallest value subtracted. The program is to ask for the number of points and then read in that many points.

  • In MATLAB, ask the user to input a matrix of any size. Ensure that the user...

    In MATLAB, ask the user to input a matrix of any size. Ensure that the user inputs a positive, integer matrix. If there is an incorrect input, ask them for a matrix again. Use Loops to do this. Using loops, find the sum of all prime numbers present in the user-entered matrix. You must not use the built-in isprime function to do this. Use loops. (The number 1 may count as as a prime number) Example Matrix: [1 2 3;...

  • write a program to ask the user if he or she wants to know about their...

    write a program to ask the user if he or she wants to know about their birth stone. if they do, then display the 12 months and allow user to select the month of thier choice. give them info using their birth stone

  • For a given list ask user if he/she wants to create a new list that repeats...

    For a given list ask user if he/she wants to create a new list that repeats n‐times itself. If Yes‐ create a new list that repeats itself n‐times, (n is user specified). ask user(use list and while) Python

  • In C plus plus Objective: Create an array of numbers based upon user input. Program logic:...

    In C plus plus Objective: Create an array of numbers based upon user input. Program logic: Ask the user for how big to size the array. Create an array based upon that size. Ask for a number, add that number to the array. Repeat adding to the end until all numbers have been entered or until they enter -1 for the number. Print the list.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT