Question

Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following:
Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE UPVOTE

I have included both Funtion to find maximum integer and Function to find minimum integer seperately.

I have included the explanation in comments.

Here is the code to find the minimum integer with function.

#include <iostream>
using namespace std;

int MinToFind(int a[],int n) //function to find smallest integer
{
        int i, min;
        min = a[0];// thinking that first number is minimum
        for(i=1;i<n;i++)
        {
                if(a[i]<min)// //if present number is smaller than minimum number
                        min =a[i];//smallest is assigned to number
        }
        return min; //returns to function
}
int main()
{
        int i, array[4], size=4, min;  // initializing int, array size and min

        cout<<"Enter four integers\n";
        for(i=0;i<size;i++)
        cin>>array[i];

        min = MinToFind(array,size); //min function is being called where we declared it

        // max element is printed
        cout<<"Smallest integer is " << min << "\n";

return 0;
}

Screenshot to the output:

main.cpp 1 #include <iostream> 2 using namespace std; 3 4. int MinToFind(int a[], int n) //function to find smallest integer


Here is the code to find the maximum integer with function.

#include <iostream>
using namespace std;
int MaxToFind(int a[],int n) //function to find largest integer
{
        int i, max;
        max = a[0];// thinking that first number is maximum
        for(i=1;i<n;i++)
        {
                if(a[i]>max) //if present number is greater than maximum number
                        max =a[i]; //max is assigned to number
        }
        return max; //returns to function
}

int main()
{
        int i, array[4], size=4, min; // initializing int, array size and max

        cout<<"Enter four integers\n";
        for(i=0;i<size;i++)
        cin>>array[i];

        max = MaxToFind(array,size); //max function is being called where we declared it

        // max element is printed
        cout<<"Largest integer is " << max << "\n";


return 0;
}

Screenshot to the output:

main.cpp 1 #include <iostream> 3 int MaxTofind(int ai], int n) //functiðh to find largest integer 5 6 int i, max; max = a[@];

PLEASE UPVOTE. COMMENT IF YOU HAVE ANY DOUBTS

Add a comment
Know the answer?
Add Answer to:
Write a complete C++ program to ask the user to enter 4 integers. The program must...
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
  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the LARGEST integer among them and print it on the screen. Typical output screen should be as following: Note: the code must contain function to find the LARGEST number. Enter four integers 1 2 4 0 Largest integer is 4

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the largest integer among them and print it on the screen. Typical output screen should be as following: Note: the code must contain function to find the largest number. Enter four integers 1 2 4 0 Largest integer is 4 03 (35 points)

  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • In Java Write a program that will ask the user for integers and print if the...

    In Java Write a program that will ask the user for integers and print if the integer is positive, negative or zero. The program should continue asking for integer until the user enters a negative value.

  • C++ Write a program that asks user to input three positive integers one at a time,...

    C++ Write a program that asks user to input three positive integers one at a time, then compute and output the largest entered number. Use if-else statements for three integer comparison and use for loops for a user validation. Example output: Enter an integer: -7 Invalid! Number must be positive. Enter an integer: -2 Invalid! Number must be positive. Enter an integer: 5 Enter an integer: 7 Enter an integer: 1 Largest number: 7

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a program that asks the user to enter 1000 integers to be stored in an...

    Write a program that asks the user to enter 1000 integers to be stored in an array called "numbers". Since the same integer might occur (exist) in the array multiple times, your program needs to fill a second array, called "Isolate" that contains all the integers from the first array but NOT REPAPTED (every integer will exist only once). Finally, your program will print the integers of the second array sorted by occurrence (occurrence is: the number of times the...

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