how can i sort numbers from ascending order and descending
order using turbo c..

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you divide two numbers in a MACRO?

715


When should the const modifier be used?

660


What is maximum size of array in c?

586


Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol

669


How can I convert a number to a string?

610






Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)

5806


What is the c value paradox and how is it explained?

578


What is mean by data types in c?

556


count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array

679


Explain what is gets() function?

637


How many types of sorting are there in c?

616


What are the types of pointers?

606


When would you use a pointer to a function?

591


What is string length in c?

618


What is getch?

633