SlideShare ist ein Scribd-Unternehmen logo
1 von 2
Generate an array that contains strings as elements. Sort this array in ascending order. (C++)
Solution
solution.cpp
#include <iostream> //header file for input output function
using namespace std; //it tells the compiler to link std arr2 space
#include <cstring> //header file for string
int main()
{ //main function
// declare two arrays arr2d arr1 with 1-Dimension
// and arr2 with 2-Dimension
char arr1[10], arr2[10][10];
// normal variables...
int i, j,noofstrings;
cout<<"Enter the number of strings required to sort ";
cin>>noofstrings;
// for loop statement
for(i=0; i<noofstrings; i++)
{
cout<<" Enter the strings of an array "<<(i+1)<<": ";
cin>>arr2[i];
}
for(i=0; i<noofstrings-1; i++)
for(j = i+1; j<noofstrings; j++)
//sorting string using strcmp()
if(strcmp(arr2[i], arr2[j])>0)
{
// strcpy - copy the strings...
// compare and swap...
strcpy(arr1, arr2[i]);
strcpy(arr2[i], arr2[j]);
strcpy(arr2[j], arr1);
}
cout<<" Sorted strings are: ";
for (i =0; i<noofstrings; i++)
cout<<" "<<arr2[i];
cout<<endl;
return 0;
}
output
sh-4.3$ main
Enter the number of strings required to sort 3
Enter the strings of an array 1: burningstar
Enter the strings of an array 2: rockstar
Enter the strings of an array 3: suddenstar
Sorted strings are:
burningstarockstar
rockstar
suddenstar

Weitere ähnliche Inhalte

Ähnlich wie Generate an array that contains strings as elements- Sort this array i.docx

1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docxchristiandean12115
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matchingShakila Mahjabin
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++NUST Stuff
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxShashiShash2
 
I have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxI have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxdelciegreeks
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationVivek Bhargav
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
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
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapseindiappsdevelopment
 

Ähnlich wie Generate an array that contains strings as elements- Sort this array i.docx (20)

7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
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
 
I have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxI have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docx
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory Allocation
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
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
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3
 

Mehr von mcarolyn

given a slab of material with a finite resistivitySolutiona) Since the.docx
given a slab of material with a finite resistivitySolutiona) Since the.docxgiven a slab of material with a finite resistivitySolutiona) Since the.docx
given a slab of material with a finite resistivitySolutiona) Since the.docxmcarolyn
 
Give two examples of how a market has been used internally within a co.docx
Give two examples of how a market has been used internally within a co.docxGive two examples of how a market has been used internally within a co.docx
Give two examples of how a market has been used internally within a co.docxmcarolyn
 
Give the conjugate base for each compound below- Acid Conjugate Base H.docx
Give the conjugate base for each compound below- Acid Conjugate Base H.docxGive the conjugate base for each compound below- Acid Conjugate Base H.docx
Give the conjugate base for each compound below- Acid Conjugate Base H.docxmcarolyn
 
Give an example of a conflict of an interest in a business setting (a.docx
Give an example of a conflict of an interest in a business setting (a.docxGive an example of a conflict of an interest in a business setting (a.docx
Give an example of a conflict of an interest in a business setting (a.docxmcarolyn
 
Give 5 importance of using relations and digraphs in computer science-.docx
Give 5 importance of using relations and digraphs in computer science-.docxGive 5 importance of using relations and digraphs in computer science-.docx
Give 5 importance of using relations and digraphs in computer science-.docxmcarolyn
 
Give 2 reasons why chlorine is often added to groundwater prior to any.docx
Give 2 reasons why chlorine is often added to groundwater prior to any.docxGive 2 reasons why chlorine is often added to groundwater prior to any.docx
Give 2 reasons why chlorine is often added to groundwater prior to any.docxmcarolyn
 
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docx
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docxgggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docx
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docxmcarolyn
 
Generally- costs incurred internally to create intangibles are A) capi.docx
Generally- costs incurred internally to create intangibles are A) capi.docxGenerally- costs incurred internally to create intangibles are A) capi.docx
Generally- costs incurred internally to create intangibles are A) capi.docxmcarolyn
 
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docx
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docxGaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docx
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docxmcarolyn
 
Functional Groups a) what is an alcohol- how do you name alcohols- b).docx
Functional Groups a) what is an alcohol- how do you name alcohols- b).docxFunctional Groups a) what is an alcohol- how do you name alcohols- b).docx
Functional Groups a) what is an alcohol- how do you name alcohols- b).docxmcarolyn
 
Future Sources- Inc- reported the following results for the year endin.docx
Future Sources- Inc- reported the following results for the year endin.docxFuture Sources- Inc- reported the following results for the year endin.docx
Future Sources- Inc- reported the following results for the year endin.docxmcarolyn
 
Given the following declarations- what result Is stored In each of the.docx
Given the following declarations- what result Is stored In each of the.docxGiven the following declarations- what result Is stored In each of the.docx
Given the following declarations- what result Is stored In each of the.docxmcarolyn
 
Given below is the partial stockholders equity section of the Balance.docx
Given below is the partial stockholders equity section of the Balance.docxGiven below is the partial stockholders equity section of the Balance.docx
Given below is the partial stockholders equity section of the Balance.docxmcarolyn
 

Mehr von mcarolyn (13)

given a slab of material with a finite resistivitySolutiona) Since the.docx
given a slab of material with a finite resistivitySolutiona) Since the.docxgiven a slab of material with a finite resistivitySolutiona) Since the.docx
given a slab of material with a finite resistivitySolutiona) Since the.docx
 
Give two examples of how a market has been used internally within a co.docx
Give two examples of how a market has been used internally within a co.docxGive two examples of how a market has been used internally within a co.docx
Give two examples of how a market has been used internally within a co.docx
 
Give the conjugate base for each compound below- Acid Conjugate Base H.docx
Give the conjugate base for each compound below- Acid Conjugate Base H.docxGive the conjugate base for each compound below- Acid Conjugate Base H.docx
Give the conjugate base for each compound below- Acid Conjugate Base H.docx
 
Give an example of a conflict of an interest in a business setting (a.docx
Give an example of a conflict of an interest in a business setting (a.docxGive an example of a conflict of an interest in a business setting (a.docx
Give an example of a conflict of an interest in a business setting (a.docx
 
Give 5 importance of using relations and digraphs in computer science-.docx
Give 5 importance of using relations and digraphs in computer science-.docxGive 5 importance of using relations and digraphs in computer science-.docx
Give 5 importance of using relations and digraphs in computer science-.docx
 
Give 2 reasons why chlorine is often added to groundwater prior to any.docx
Give 2 reasons why chlorine is often added to groundwater prior to any.docxGive 2 reasons why chlorine is often added to groundwater prior to any.docx
Give 2 reasons why chlorine is often added to groundwater prior to any.docx
 
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docx
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docxgggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docx
gggggggggggggggggggggggggggggggggSolutionElectrical engineering is a f.docx
 
Generally- costs incurred internally to create intangibles are A) capi.docx
Generally- costs incurred internally to create intangibles are A) capi.docxGenerally- costs incurred internally to create intangibles are A) capi.docx
Generally- costs incurred internally to create intangibles are A) capi.docx
 
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docx
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docxGaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docx
GaP is an intrinsic semiconductor with a band gap of 2-26 eV- How woul.docx
 
Functional Groups a) what is an alcohol- how do you name alcohols- b).docx
Functional Groups a) what is an alcohol- how do you name alcohols- b).docxFunctional Groups a) what is an alcohol- how do you name alcohols- b).docx
Functional Groups a) what is an alcohol- how do you name alcohols- b).docx
 
Future Sources- Inc- reported the following results for the year endin.docx
Future Sources- Inc- reported the following results for the year endin.docxFuture Sources- Inc- reported the following results for the year endin.docx
Future Sources- Inc- reported the following results for the year endin.docx
 
Given the following declarations- what result Is stored In each of the.docx
Given the following declarations- what result Is stored In each of the.docxGiven the following declarations- what result Is stored In each of the.docx
Given the following declarations- what result Is stored In each of the.docx
 
Given below is the partial stockholders equity section of the Balance.docx
Given below is the partial stockholders equity section of the Balance.docxGiven below is the partial stockholders equity section of the Balance.docx
Given below is the partial stockholders equity section of the Balance.docx
 

Kürzlich hochgeladen

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 

Kürzlich hochgeladen (20)

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 

Generate an array that contains strings as elements- Sort this array i.docx

  • 1. Generate an array that contains strings as elements. Sort this array in ascending order. (C++) Solution solution.cpp #include <iostream> //header file for input output function using namespace std; //it tells the compiler to link std arr2 space #include <cstring> //header file for string int main() { //main function // declare two arrays arr2d arr1 with 1-Dimension // and arr2 with 2-Dimension char arr1[10], arr2[10][10]; // normal variables... int i, j,noofstrings; cout<<"Enter the number of strings required to sort "; cin>>noofstrings; // for loop statement for(i=0; i<noofstrings; i++) { cout<<" Enter the strings of an array "<<(i+1)<<": "; cin>>arr2[i]; } for(i=0; i<noofstrings-1; i++) for(j = i+1; j<noofstrings; j++) //sorting string using strcmp() if(strcmp(arr2[i], arr2[j])>0) { // strcpy - copy the strings... // compare and swap... strcpy(arr1, arr2[i]); strcpy(arr2[i], arr2[j]); strcpy(arr2[j], arr1); }
  • 2. cout<<" Sorted strings are: "; for (i =0; i<noofstrings; i++) cout<<" "<<arr2[i]; cout<<endl; return 0; } output sh-4.3$ main Enter the number of strings required to sort 3 Enter the strings of an array 1: burningstar Enter the strings of an array 2: rockstar Enter the strings of an array 3: suddenstar Sorted strings are: burningstarockstar rockstar suddenstar