From 38d0f62d41171f8956e6464c97b02bb947b0b7f7 Mon Sep 17 00:00:00 2001 From: Monalika Date: Wed, 26 May 2021 16:26:24 +0530 Subject: [PATCH 1/2] Create Sorting names in an alphabetical order.cpp --- Sorting names in an alphabetical order.cpp | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Sorting names in an alphabetical order.cpp diff --git a/Sorting names in an alphabetical order.cpp b/Sorting names in an alphabetical order.cpp new file mode 100644 index 0000000..eaa5384 --- /dev/null +++ b/Sorting names in an alphabetical order.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; + +//function to print the array +void print(vector names){ + printf("printing ........\n"); + for(int i=0;i alphabaticallySort(vector a){ + int n=a.size(); + //mycomp function is the defined function which + //sorts the strings in alphabatical order + sort(a.begin(),a.end(),mycomp); + return a; +} + +int main() +{ + int n; + printf("enter number of names to be added: "); + scanf("%d",&n); + + //creating a vector of strings + //vector to store strings(names) + vector names; + string name; + printf("enter names: \n"); + //taking input + for(int i=0;i>name; + //insert names into the vector + names.push_back(name); + } + + printf("\nbefore sorting\n"); + print(names); + + //function to sort names alphabetically + names=alphabaticallySort(names); + + printf("after alphabetical sorting\n"); + print(names); + + return 0; +} From d2c5db646c261aa87f5f2beff4f4bc20af35056f Mon Sep 17 00:00:00 2001 From: Monalika Date: Wed, 26 May 2021 16:31:53 +0530 Subject: [PATCH 2/2] Create Code to Swap Two Numbers without using third variable --- ...p Two Numbers without using third variable | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Code to Swap Two Numbers without using third variable diff --git a/Code to Swap Two Numbers without using third variable b/Code to Swap Two Numbers without using third variable new file mode 100644 index 0000000..ebca4d2 --- /dev/null +++ b/Code to Swap Two Numbers without using third variable @@ -0,0 +1,27 @@ +/* C++ Program to Swap Two Numbers without using third variable */ + +#include +using namespace std; + +int main() +{ + + int a,b ; + + cout<<"Enter 1st number :: "; + cin>>a; + cout<<"\nEnter 2nd number :: "; + cin>>b; + + cout << "\nBefore swapping, Numbers are :: " << endl; + cout << "\n\ta = " << a << ", b = " << b << endl; + + a = a + b; + b = a - b; + a = a - b; + + cout << "\nAfter swapping, Numbers are :: " << endl; + cout << "\n\ta = " << a << ", b = " << b << endl; + + return 0; +}