SlideShare ist ein Scribd-Unternehmen logo
1 von 2
In C++ please,
Problem 1: Write a function that accepts an int array and the array’s size as arguments. The
function should create a copy of the array (using dynamic allocation), except that the element
values should be reversed in the copy. The function should return a pointer to the new array.
Demonstrate the function in a complete program.
Solution
ReverseArray.cpp
#include <iostream>
using namespace std;
int* reverseArray(int a[], int size);
int main()
{
int n;
cout << "Enter Array Size " << endl;
cin >> n;
int a[n];
for(int i=0; i<n; i++){
cout<<"Enter Element :"<<endl;
cin >> a[i];
}
cout<<"Array Before Reverse is "<<endl;
for(int i=0; i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
int *reverseArr = reverseArray(a, n);
cout<<"Reverse Array is "<<endl;
for(int i=0; i<n;i++){
cout<<reverseArr[i]<<" ";
}
cout<<endl;
return 0;
}
int* reverseArray(int a[], int size){
int *array;
int j=0;
array=(int *) malloc(size*sizeof(int));
for(int i=size-1;i>=0; i--,j++){
array[j]= a[i];
}
return array;
}
Output:
Enter Array Size
5
Enter Element :
3
Enter Element :
4
Enter Element :
2
Enter Element :
1
Enter Element :
5
Array Before Reverse is
3 4 2 1 5
Reverse Array is
5 1 2 4 3

Weitere ähnliche Inhalte

Ähnlich wie In C++ please- Problem 1- Write a function that accepts an int array a.docx

Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxarjurakibulhasanrrr7
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxShashiShash2
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
using C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxusing C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxslyndon
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptxNagasaiT
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 

Ähnlich wie In C++ please- Problem 1- Write a function that accepts an int array a.docx (17)

C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
using C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxusing C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docx
 
Lab 1
Lab 1Lab 1
Lab 1
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
cpp promo ppt.pptx
cpp promo ppt.pptxcpp promo ppt.pptx
cpp promo ppt.pptx
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 

Mehr von tristans3

In a symmetric multiprocessor configuration- AH processors can perform.docx
In a symmetric multiprocessor configuration- AH processors can perform.docxIn a symmetric multiprocessor configuration- AH processors can perform.docx
In a symmetric multiprocessor configuration- AH processors can perform.docxtristans3
 
In consumer behavior we discussed innovators- opinion leaders- and mar.docx
In consumer behavior we discussed innovators- opinion leaders- and mar.docxIn consumer behavior we discussed innovators- opinion leaders- and mar.docx
In consumer behavior we discussed innovators- opinion leaders- and mar.docxtristans3
 
In chapter 2- 5 objectives of memory management were discussed- In Cha.docx
In chapter 2- 5 objectives of memory management were discussed- In Cha.docxIn chapter 2- 5 objectives of memory management were discussed- In Cha.docx
In chapter 2- 5 objectives of memory management were discussed- In Cha.docxtristans3
 
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docx
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docxIn certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docx
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docxtristans3
 
In c- Topic pointers Why do they call it dereferencing- As in derefer.docx
In c- Topic pointers  Why do they call it dereferencing- As in derefer.docxIn c- Topic pointers  Why do they call it dereferencing- As in derefer.docx
In c- Topic pointers Why do they call it dereferencing- As in derefer.docxtristans3
 
In C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docxIn C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docxtristans3
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxtristans3
 
In an alternative universe- all rules governing quantum numbers and th.docx
In an alternative universe- all rules governing quantum numbers and th.docxIn an alternative universe- all rules governing quantum numbers and th.docx
In an alternative universe- all rules governing quantum numbers and th.docxtristans3
 
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docx
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docxIn a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docx
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docxtristans3
 
In a Classical model of the macroeconomy- the equilibrating mechanism.docx
In a Classical model of the macroeconomy- the equilibrating mechanism.docxIn a Classical model of the macroeconomy- the equilibrating mechanism.docx
In a Classical model of the macroeconomy- the equilibrating mechanism.docxtristans3
 
In 2012- Shurtleff estimates that warranty costs in the following year.docx
In 2012- Shurtleff estimates that warranty costs in the following year.docxIn 2012- Shurtleff estimates that warranty costs in the following year.docx
In 2012- Shurtleff estimates that warranty costs in the following year.docxtristans3
 
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docx
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docxIn 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docx
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docxtristans3
 
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docx
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docxIn 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docx
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docxtristans3
 
Impulse and momentum are two two different parameters- Explain these p.docx
Impulse and momentum are two two different parameters- Explain these p.docxImpulse and momentum are two two different parameters- Explain these p.docx
Impulse and momentum are two two different parameters- Explain these p.docxtristans3
 
Implementation of EHR Discuss the advantages and disadvantages associa.docx
Implementation of EHR Discuss the advantages and disadvantages associa.docxImplementation of EHR Discuss the advantages and disadvantages associa.docx
Implementation of EHR Discuss the advantages and disadvantages associa.docxtristans3
 
Implementing a new AIS system could prove to be beneficial or detrimen.docx
Implementing a new AIS system could prove to be beneficial or detrimen.docxImplementing a new AIS system could prove to be beneficial or detrimen.docx
Implementing a new AIS system could prove to be beneficial or detrimen.docxtristans3
 
Im creating a stack class using generics- what should my peek method l.docx
Im creating a stack class using generics- what should my peek method l.docxIm creating a stack class using generics- what should my peek method l.docx
Im creating a stack class using generics- what should my peek method l.docxtristans3
 
ii)State whether you would expect the following Group 13 metal cations.docx
ii)State whether you would expect the following Group 13 metal cations.docxii)State whether you would expect the following Group 13 metal cations.docx
ii)State whether you would expect the following Group 13 metal cations.docxtristans3
 
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docx
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docxIMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docx
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docxtristans3
 
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docxtristans3
 

Mehr von tristans3 (20)

In a symmetric multiprocessor configuration- AH processors can perform.docx
In a symmetric multiprocessor configuration- AH processors can perform.docxIn a symmetric multiprocessor configuration- AH processors can perform.docx
In a symmetric multiprocessor configuration- AH processors can perform.docx
 
In consumer behavior we discussed innovators- opinion leaders- and mar.docx
In consumer behavior we discussed innovators- opinion leaders- and mar.docxIn consumer behavior we discussed innovators- opinion leaders- and mar.docx
In consumer behavior we discussed innovators- opinion leaders- and mar.docx
 
In chapter 2- 5 objectives of memory management were discussed- In Cha.docx
In chapter 2- 5 objectives of memory management were discussed- In Cha.docxIn chapter 2- 5 objectives of memory management were discussed- In Cha.docx
In chapter 2- 5 objectives of memory management were discussed- In Cha.docx
 
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docx
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docxIn certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docx
In certain chlorophyll cofactors the Mg2+ is axially coordinated by th.docx
 
In c- Topic pointers Why do they call it dereferencing- As in derefer.docx
In c- Topic pointers  Why do they call it dereferencing- As in derefer.docxIn c- Topic pointers  Why do they call it dereferencing- As in derefer.docx
In c- Topic pointers Why do they call it dereferencing- As in derefer.docx
 
In C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docxIn C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docx
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
In an alternative universe- all rules governing quantum numbers and th.docx
In an alternative universe- all rules governing quantum numbers and th.docxIn an alternative universe- all rules governing quantum numbers and th.docx
In an alternative universe- all rules governing quantum numbers and th.docx
 
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docx
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docxIn a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docx
In a nonpolar covalent bond--- Electrons are shared unevenly Electrons.docx
 
In a Classical model of the macroeconomy- the equilibrating mechanism.docx
In a Classical model of the macroeconomy- the equilibrating mechanism.docxIn a Classical model of the macroeconomy- the equilibrating mechanism.docx
In a Classical model of the macroeconomy- the equilibrating mechanism.docx
 
In 2012- Shurtleff estimates that warranty costs in the following year.docx
In 2012- Shurtleff estimates that warranty costs in the following year.docxIn 2012- Shurtleff estimates that warranty costs in the following year.docx
In 2012- Shurtleff estimates that warranty costs in the following year.docx
 
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docx
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docxIn 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docx
In 2000- June- A 75-year-old widow- creates an irrevocable trust namin.docx
 
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docx
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docxIn 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docx
In 2007- Heuy-'s actual income was $70-000- equal to his lifetime annu.docx
 
Impulse and momentum are two two different parameters- Explain these p.docx
Impulse and momentum are two two different parameters- Explain these p.docxImpulse and momentum are two two different parameters- Explain these p.docx
Impulse and momentum are two two different parameters- Explain these p.docx
 
Implementation of EHR Discuss the advantages and disadvantages associa.docx
Implementation of EHR Discuss the advantages and disadvantages associa.docxImplementation of EHR Discuss the advantages and disadvantages associa.docx
Implementation of EHR Discuss the advantages and disadvantages associa.docx
 
Implementing a new AIS system could prove to be beneficial or detrimen.docx
Implementing a new AIS system could prove to be beneficial or detrimen.docxImplementing a new AIS system could prove to be beneficial or detrimen.docx
Implementing a new AIS system could prove to be beneficial or detrimen.docx
 
Im creating a stack class using generics- what should my peek method l.docx
Im creating a stack class using generics- what should my peek method l.docxIm creating a stack class using generics- what should my peek method l.docx
Im creating a stack class using generics- what should my peek method l.docx
 
ii)State whether you would expect the following Group 13 metal cations.docx
ii)State whether you would expect the following Group 13 metal cations.docxii)State whether you would expect the following Group 13 metal cations.docx
ii)State whether you would expect the following Group 13 metal cations.docx
 
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docx
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docxIMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docx
IMF in Greece- Good or bad for the country- Why-SolutionIMF is interna.docx
 
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx
2- What is a colloid- Why is it difficult to filter a colloid- 3- What.docx
 

Kürzlich hochgeladen

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Kürzlich hochgeladen (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

In C++ please- Problem 1- Write a function that accepts an int array a.docx

  • 1. In C++ please, Problem 1: Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array (using dynamic allocation), except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function in a complete program. Solution ReverseArray.cpp #include <iostream> using namespace std; int* reverseArray(int a[], int size); int main() { int n; cout << "Enter Array Size " << endl; cin >> n; int a[n]; for(int i=0; i<n; i++){ cout<<"Enter Element :"<<endl; cin >> a[i]; } cout<<"Array Before Reverse is "<<endl; for(int i=0; i<n;i++){ cout<<a[i]<<" "; } cout<<endl; int *reverseArr = reverseArray(a, n); cout<<"Reverse Array is "<<endl; for(int i=0; i<n;i++){ cout<<reverseArr[i]<<" "; }
  • 2. cout<<endl; return 0; } int* reverseArray(int a[], int size){ int *array; int j=0; array=(int *) malloc(size*sizeof(int)); for(int i=size-1;i>=0; i--,j++){ array[j]= a[i]; } return array; } Output: Enter Array Size 5 Enter Element : 3 Enter Element : 4 Enter Element : 2 Enter Element : 1 Enter Element : 5 Array Before Reverse is 3 4 2 1 5 Reverse Array is 5 1 2 4 3