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

When should the volatile modifier be used?

0 Answers  


What are the commands should be given before weiting C Program i.e, Cd.. like

4 Answers   IBM, Infonet, Satyam, Tech Mahindra,


Function to find the given number is a power of 2 or not?

20 Answers   Motorola, nvidia,


what is link list?

3 Answers  


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

0 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


Program to find larger of the two numbers without using if-else,while,for,switch

11 Answers   iNautix, Wipro,


What is the time and space complexities of merge sort and when is it preferred over quick sort?

0 Answers   Amazon,


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

0 Answers  


Explain what happens if you free a pointer twice?

0 Answers  


How can you dynamically allocate memory in C?

2 Answers  


enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }

4 Answers   ME,


Categories