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
What are the 4 types of organizational structures?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What is n in c?
How can I access an I o board directly?
What are the different types of pointers used in c language?
i want to know the procedure of qualcomm for getting a job through offcampus
What are the types of variables in c?
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration
Can a pointer be volatile in c?
Write a program to print ASCII code for a given digit.
how could explain about job profile
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
Explain how do you view the path?
How can you allocate arrays or structures bigger than 64K?