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

Explain void pointer?

0 Answers  


Question 1: You want to conduct a survey within your classroom, on the quality of canteen’s food. You ask each of your class fellows to rank the quality of food between 1 and 5 (1 representing excellent quality and 5 representing worst quality). During the survey, you make a list containing the roll# of student and the opinion given by that student. The list can be as follow Roll # Opinion 234 1 235 1 236 5 237 1 238 2 239 3 240 5 241 5 242 1 To get the results of the survey, you need to determine the frequency of each opinion value. The frequency of an opinion is determined by counting the number of students giving that opinion. For example, for the above list the frequency of opinion value 1 is 4 and frequency of opinion value 4 is 0. After getting the frequency of each opinion, you can easily judge about the quality of the food by seeing through the frequency of each opinion. You need to develop a program to calculate the results of this survey. The program inputs the opinion of 50 students and counts the frequency of each opinion. It then displays a report showing the frequency of each opinion. Sample output: Opinion Frequency Remarks 1 5 Excellent 2 10 Good 3 15 Normal 4 10 Bad 5 10 Really bad

1 Answers  


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

0 Answers   HCL,


how will you write a program on linked lists using JAVA programming???????????

1 Answers   Keane India Ltd,


plz answer..... a program that reads non-negative integer and computes and prints its factorial

2 Answers  






What is a pointer in c?

0 Answers  


what is purpose of fflush(stdin) function

4 Answers  


cavium networks written test pattern ..

0 Answers   Cavium Networks,


What are the application of void data type in c?

0 Answers  


What is the data segment that is followed by c?

0 Answers  


the maximum width of a c variable name can be a) 6 characters b) 8 characters c) 10 characters d) 20 characters

2 Answers  


#include<stdio.h> void main() { int a=5,b=6,c; int x=(a<b)+7; int y=(x==7)*9; int z=(c=x+y)*2; printf("%h %h %h",x,y,z); } What is the output? Explain it.

8 Answers   IBM,


Categories