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
How will you divide two numbers in a MACRO?
When should the const modifier be used?
What is maximum size of array in c?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
How can I convert a number to a string?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
What is the c value paradox and how is it explained?
What is mean by data types in c?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
Explain what is gets() function?
How many types of sorting are there in c?
What are the types of pointers?
When would you use a pointer to a function?
What is string length in c?
What is getch?