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 |
What is difference between scanf and gets?
What is the role of this pointer?
Can we replace the struct function in tree syntax with a union?
#include <stdio.h> #define sqr(x) (x*x) int main() { int x=2; printf("value of x=%d",sqr(x+1)); } What is the value of x?
16 Answers Accel Frontline, Opera, Oracle,
if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how?
What are global variables and how do you declare them?
write a program which counts a product of array elements lower than 10.
why i join syntel?
23 Answers ABC, Syntel, TCS,
Which command is more efficient? *(ptr+1) or ptr[1]
While(1) { } when this loop get terminate is it a infinite loop?
what is ur strangth & weekness
0 Answers Cognizant, LG Soft, NetEnrich,
When should structures be passed by values or by references?