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



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

Post New Answer

More C Interview Questions

code for replace tabs with equivalent number of blanks

0 Answers   Bosch,


create an SINGLE LINKED LISTS and reverse the data in the lists completely

3 Answers  


write a program that will print %d in the output screen??

9 Answers   Infosys,


How does pointer work in c?

0 Answers  


How can I implement a delay, or time a users response, with sub-second resolution?

0 Answers  






what is the need for main function in c?

5 Answers  


what is the difference between c and c++?

7 Answers  


How can I do graphics in c?

0 Answers  


How can I read and write comma-delimited text?

0 Answers  


whether itis a structured language?

1 Answers   Microsoft,


what is ram?

3 Answers   TCS,


In which header file is the null macro defined?

0 Answers  


Categories