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 |
Should I learn c before c++?
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?
wite a programme in c to linear search a data using flag and without using flags?
main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }
write a program that accepts 3 numbers from the user. dispaly the values in a descending order.
compare array with pointer?
What is the scope of static variables in c language?
#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); }
differnce between do and do while
Is it acceptable to declare/define a variable in a c header?
How can I manipulate individual bits?
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