SlideShare a Scribd company logo
1 of 2
Download to read offline
Part I: Write a program that uses a function that takes in two integers as inputand returns a
minimum value (using pass-by-value). (HINT: the prototype lookslike: int minimum(int num1,
int num2);
Part II: Modify your original program to include a function that take in fourintegers; two of
which are passed-by-value, and the other two are passed-by-reference. The pass-by-reference
integers are the min and max of the two pass-by-value integers. Find the min and max and
"return" the values back to main.The prototype here is: void minmax(int &min, int &max, int
num1, int num2);
Solution
Question1:
#include
using namespace std;
int minimum(int num1, int num2);
int main()
{
int num1, num2, min;
cout<<"Enter first number: ";
cin >> num1;
cout<<"Enter second number: ";
cin >> num2;
min = minimum(num1, num2);
cout<<"The minimum number is "<< min<
using namespace std;
void minmax(int &min, int &max, int num1, int num2);
int main()
{
int num1, num2, min, max;
cout<<"Enter first number: ";
cin >> num1;
cout<<"Enter second number: ";
cin >> num2;
minmax(min, max, num1, num2);
cout<<"The minimum number is "<< min< num2){
min = num2;
max = num1;
}
else{
min = num1;
max = num1;
}
}
Output:
Enter first number:
6
Enter second number:
5
The minimum number is
5
The maximum number is
6
sh-4.3$ g++ -std=c++11 -o main
*.cpp
sh-4.3$
main
Enter first number:
4
Enter second number:
5
The minimum number is 4

More Related Content

Similar to Part I Write a program that uses a function that takes in two integ.pdf

Create a C program which performs the addition of two comple.pdf
Create a C program which performs the addition of two comple.pdfCreate a C program which performs the addition of two comple.pdf
Create a C program which performs the addition of two comple.pdf
devangmittal4
 
Look at the following main function- Write a program using the main fu.docx
Look at the following main function- Write a program using the main fu.docxLook at the following main function- Write a program using the main fu.docx
Look at the following main function- Write a program using the main fu.docx
hendriciraida
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
AASTHA76
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
arihantcomputersddn
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdfComplete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
americanopticalscbe
 

Similar to Part I Write a program that uses a function that takes in two integ.pdf (17)

c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Write a recursive C++ function that inputs a nonnegative integer n an.docx
 Write a recursive C++ function that inputs a nonnegative integer n an.docx Write a recursive C++ function that inputs a nonnegative integer n an.docx
Write a recursive C++ function that inputs a nonnegative integer n an.docx
 
Find attached the code to implement the following two functions- 1- In.pdf
Find attached the code to implement the following two functions- 1- In.pdfFind attached the code to implement the following two functions- 1- In.pdf
Find attached the code to implement the following two functions- 1- In.pdf
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
Create a C program which performs the addition of two comple.pdf
Create a C program which performs the addition of two comple.pdfCreate a C program which performs the addition of two comple.pdf
Create a C program which performs the addition of two comple.pdf
 
Look at the following main function- Write a program using the main fu.docx
Look at the following main function- Write a program using the main fu.docxLook at the following main function- Write a program using the main fu.docx
Look at the following main function- Write a program using the main fu.docx
 
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIIntro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
 
Lab-11-C-Problems.pptx
Lab-11-C-Problems.pptxLab-11-C-Problems.pptx
Lab-11-C-Problems.pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdfComplete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
 

More from Rahul04August

Which one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdfWhich one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdf
Rahul04August
 
There is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdfThere is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdf
Rahul04August
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
the consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdfthe consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdf
Rahul04August
 
Technology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdfTechnology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdf
Rahul04August
 
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdfSuppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Rahul04August
 
Questions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdfQuestions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdf
Rahul04August
 

More from Rahul04August (20)

Why soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdfWhy soot formation is only observed in diffusion flames I need deta.pdf
Why soot formation is only observed in diffusion flames I need deta.pdf
 
Which one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdfWhich one is the correct answer Which is not a KEY characteristic o.pdf
Which one is the correct answer Which is not a KEY characteristic o.pdf
 
Which of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdfWhich of the following statements about prokaryotes is falsea) Prok.pdf
Which of the following statements about prokaryotes is falsea) Prok.pdf
 
What type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdfWhat type of computer would integrate the system unit (chassis and co.pdf
What type of computer would integrate the system unit (chassis and co.pdf
 
What is the physical meaning of each term in the below equation DM_.pdf
What is the physical meaning of each term in the below equation  DM_.pdfWhat is the physical meaning of each term in the below equation  DM_.pdf
What is the physical meaning of each term in the below equation DM_.pdf
 
What is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdfWhat is the difference between a nucleotide sequence and a protein s.pdf
What is the difference between a nucleotide sequence and a protein s.pdf
 
types of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdftypes of becterias and diseases that come from of wrong storing food.pdf
types of becterias and diseases that come from of wrong storing food.pdf
 
Two white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdfTwo white mice mate. The male has both a white and black fur-colo.pdf
Two white mice mate. The male has both a white and black fur-colo.pdf
 
Two chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdfTwo chains are available to hold up an object. A student arranges t.pdf
Two chains are available to hold up an object. A student arranges t.pdf
 
This is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdfThis is a modeling problem in Interger programming.We have a probl.pdf
This is a modeling problem in Interger programming.We have a probl.pdf
 
There is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdfThere is a surge of mergers and acquisitions among television networ.pdf
There is a surge of mergers and acquisitions among television networ.pdf
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
the input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdfthe input to a frequency translation system has a bandwidth of 19 to.pdf
the input to a frequency translation system has a bandwidth of 19 to.pdf
 
The First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdfThe First genetic maps used genes as markers becauseplease answer.pdf
The First genetic maps used genes as markers becauseplease answer.pdf
 
the consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdfthe consistent joining of two specific bases in nucleotides within DN.pdf
the consistent joining of two specific bases in nucleotides within DN.pdf
 
Technology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdfTechnology is advancing at an alarming rate. We now have more method.pdf
Technology is advancing at an alarming rate. We now have more method.pdf
 
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdfSuppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
Suppose a mutant fruit fly with blue eyes was recently discovered. I.pdf
 
Students should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdfStudents should research and identify an article on the subject of s.pdf
Students should research and identify an article on the subject of s.pdf
 
Questions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdfQuestions1. Research the Master Boot Record. Write a long paragra.pdf
Questions1. Research the Master Boot Record. Write a long paragra.pdf
 
Problem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdfProblem Find the z-transform, in closed form, of the number sequence .pdf
Problem Find the z-transform, in closed form, of the number sequence .pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

Part I Write a program that uses a function that takes in two integ.pdf

  • 1. Part I: Write a program that uses a function that takes in two integers as inputand returns a minimum value (using pass-by-value). (HINT: the prototype lookslike: int minimum(int num1, int num2); Part II: Modify your original program to include a function that take in fourintegers; two of which are passed-by-value, and the other two are passed-by-reference. The pass-by-reference integers are the min and max of the two pass-by-value integers. Find the min and max and "return" the values back to main.The prototype here is: void minmax(int &min, int &max, int num1, int num2); Solution Question1: #include using namespace std; int minimum(int num1, int num2); int main() { int num1, num2, min; cout<<"Enter first number: "; cin >> num1; cout<<"Enter second number: "; cin >> num2; min = minimum(num1, num2); cout<<"The minimum number is "<< min< using namespace std; void minmax(int &min, int &max, int num1, int num2); int main() { int num1, num2, min, max; cout<<"Enter first number: "; cin >> num1; cout<<"Enter second number: "; cin >> num2; minmax(min, max, num1, num2); cout<<"The minimum number is "<< min< num2){
  • 2. min = num2; max = num1; } else{ min = num1; max = num1; } } Output: Enter first number: 6 Enter second number: 5 The minimum number is 5 The maximum number is 6 sh-4.3$ g++ -std=c++11 -o main *.cpp sh-4.3$ main Enter first number: 4 Enter second number: 5 The minimum number is 4