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

What is difference between scanf and gets?

0 Answers  


What is the role of this pointer?

0 Answers  


Can we replace the struct function in tree syntax with a union?

0 Answers   Huawei,


#include <stdio.h> #define sqr(x) (x*x) int main() { int x=2; printf("value of x=%d",sqr(x+1)); } What is the value of x?

16 Answers   Accel Frontline, Opera, Oracle,


if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how?

9 Answers   Wipro,






What are global variables and how do you declare them?

0 Answers  


write a program which counts a product of array elements lower than 10.

1 Answers  


why i join syntel?

23 Answers   ABC, Syntel, TCS,


Which command is more efficient? *(ptr+1) or ptr[1]

3 Answers  


While(1) { } when this loop get terminate is it a infinite loop?

5 Answers  


what is ur strangth & weekness

0 Answers   Cognizant, LG Soft, NetEnrich,


When should structures be passed by values or by references?

0 Answers   Adobe,


Categories