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; +} 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; +}