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
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
write a program to rearrange the array such way that all even elements should come first and next come odd
Under what circumstances does a name clash occur?
Can you please explain the difference between syntax vs logical error?
What does struct node * mean?
What is variables in c?
Why n++ execute faster than n+1 ?
why return type of main is not necessary in linux
What is header file definition?
How many levels of indirection in pointers can you have in a single declaration?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
What is the difference between functions abs() and fabs()?
What are the types of arrays in c?
Why does not c have an exponentiation operator?