how can i sort numbers from ascending order and descending
order using turbo c..
Answer / neha
If you are using the String class to store your names then you can use the < or > operators to compare the order, alphabetically, they appear in.
String names[3];
int numberOfNames = 3;
names[0] = "abc";
names[1] = "dfg";
names[2] = "hij";
printf("before %s%s%s\n", names[0],names[1],names[2]);
for( int i = 0; i < numberOfNames-1; i++ )
{
for( int j = 0; j < numberOfNames; j++ )
{
if( names[j] < names[j+1] )
{
names[j].swap( names[j+1] );
}
}
}
printf("after%s%s%s\n", names[0],names[1],names[2]);
output:
before abcdfghij
after hijdfgabc
| Is This Answer Correct ? | 4 Yes | 6 No |
How many levels deep can include files be nested?
c program to compute AREA under integral
how to make program without <> in libray.
Should a function contain a return statement if it does not return a value?
Difference between data structure and data base.
7 Answers CTS, Value Labs, Zoho,
What is the difference b/w Structure & Array?
what is the difference between 123 and 0123 in c?
What is the purpose of 'register' keyword in c language?
Why double pointer is used in c?
How do you declare a variable that will hold string values?
What is s in c?
What are operators in c?