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 |
When should the volatile modifier be used?
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?
what is link list?
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
Juxtapose the use of override with new. What is shadowing?
Program to find larger of the two numbers without using if-else,while,for,switch
What is the time and space complexities of merge sort and when is it preferred over quick sort?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
Explain what happens if you free a pointer twice?
How can you dynamically allocate memory in C?
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }