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...

  • Write a program that asks the user how many integers they would like to enter. You...

    Write a program that asks the user how many integers they would like to enter. You can assume they will enter an integer >= 1. The program will then prompt the user to enter that many integers. After all the numbers have been entered, the program should display the largest and smallest of those numbers (no, you cannot use lists, or any other material we haven't covered). When you run your program it should match the following format: How many...

  • Write a program that finds the largest and smallest of four integers entered by user. Enter...

    Write a program that finds the largest and smallest of four integers entered by user. Enter four integers: 21 43 10 35 Largest: 43 Smallest: 10 (Must be done in Code::Blocks C++)

  • 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 program that lets the user enter 10 values into an array. The program should...

    Write a program that lets the user enter 10 values into an array. The program should then display the largest and the smallest values stored in the array. The program should display the following message to the user at the beginning "This program will ask you to enter ten values. Then it will determine the largest and smallest of the values you entered.Please enter 10 integers separated by spaces: " And then after user entered the numbers, it should display...

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