how can i sort numbers from ascending order and descending
order using turbo c..



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

Post New Answer

More C Interview Questions

Should I learn c before c++?

0 Answers  


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

0 Answers  


wite a programme in c to linear search a data using flag and without using flags?

3 Answers   TCS,


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }

8 Answers   Vector,


write a program that accepts 3 numbers from the user. dispaly the values in a descending order.

3 Answers  






compare array with pointer?

1 Answers  


What is the scope of static variables in c language?

0 Answers  


#include<stdio.h> #include<conio.h> # define swap(a,b) temp=a; a=b; b=temp; void main( ) { int i, j, temp; i=5; j=10; temp=0; if( i > j) swap( i, j ); printf( "%d %d %d", i, j, temp); }

9 Answers   Burning Glass,


differnce between do and do while

3 Answers   DOEACC,


Is it acceptable to declare/define a variable in a c header?

0 Answers  


How can I manipulate individual bits?

0 Answers  


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

0 Answers  


Categories