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 math functions are available for integers? For floating point?
explain what are pointers?
Is fortran still used today?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
What is include directive in c?
What is a structure member in c?
What is difference between structure and union?
What is getch () for?
What is equivalent to ++i+++j?
writ a program to compare using strcmp VIVA and viva with its output.
What is getch?
What are operators in c?
When should the const modifier be used?
What is c variable?
write a c program in such a way that if we enter the today date the output should be next day's date.