- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sorting string in Descending order C++
The sorting in ascending or descending order, however, can duly be performed by using string sort method and other means too in the C++ programming. But here, the string compare (first words with the second) and copy (copy the first word in a temp variable) method involved in the inner and outer traversing loop to put the words in descending order as following.
Example
#include<bits/stdc++.h> using namespace std; int main(){ char str[3][20]={"Ajay","Ramesh","Mahesh"}; char t[20]; int i, j; for(i=1; i<3; i++){ for(j=1; j<3; j++){ if(strcmp(str[j-1], str[j])>0){ strcpy(t, str[j-1]); strcpy(str[j-1], str[j]); strcpy(str[j], t); } } } cout<<"Sorted in Descending Order ::"; for(i=3; i>=0; i--){ cout<<" "; cout<<str[i]<<"\n"; } return 0; }
Output
This program yields the results by sorting the string in descending order after accepting three words (Ajay, Ramesh, and Mahesh) as an input as following;
Sorted in Descending Order:: Ramesh Mahesh Ajay
- Related Articles
- Sorting a vector in descending order in C++
- Sorting string in reverse order in JavaScript
- Sorting numbers in descending order but with `0`s at the start JavaScript
- C# Program to order array elements in descending order
- Sort list elements in descending order in C#
- Sort an array in descending order using C#
- Sorting one string by the order of second in JavaScript
- Sorting a String in C#
- C# program to sort an array in descending order
- Descending order in Map and Multimap of C++ STL
- C program to sort an array in descending order
- Sort MongoDB documents in descending order
- How to order by timestamp (descending order) in MongoDB
- How do you sort an array in C# in descending order?
- How to sort a Vector in descending order using STL in C++?

Advertisements