answersLogoWhite

0


Best Answer

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("befores%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("afters%s\n", names[0],names[1],names[2]);

output:

before abcdfghij

after hijdfgabc

*********************************************************************

this will give correct answer

#include

int main(){

int i,j,n;

char str[20][20],temp[20];

puts("Enter the no. of string to be sorted");

scanf("%d",&n);

for(i=0;i<=n;i++)

gets(str[i]);

for(i=0;i<=n;i++)

for(j=i+1;j<=n;j++){

if(strcmp(str[i],str[j])>0){

strcpy(temp,str[i]);

strcpy(str[i],str[j]);

strcpy(str[j],temp);

}

}

printf("The sorted string\n");

for(i=0;i<=n;i++)

puts(str[i]);

return 0;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a c program to sort ten names in descending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

To write a polynomial in standard form write the exponents of the in descending order?

Terms


Give two paragraph descending order?

First, decide on the paragraphs that you would like to use. Write them out in the descending order that you want.


Write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student?

write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student.


Write each factor as a polynomial in descending order x2 plus 14x plus 24?

The polynomial IS written in descending order.


When writing polynomial's in standard form what do you write in descending order?

Powers of their exponents


How do you write polynomials in ascending and descending order?

before and after use an conpair the results


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Write an Assembly language program which implements sorting algorithm both ascending and descending order and display those numbers with certain delay say of 5sec between successive displays?

das


Write each polynomial in descending order 36a2-49b2?

(6a + 7b)(6a - 7b)


Write a c programme to print all the even numbers in descending order?

#include(stdio.h) int main ()


Write 8x2 plus 6x - 35 as a polynomial in descending order?

Type your answer here... (2x + 5)(4x - 7)


How do you write each factor as a polynomial in descending order x3-3x2-10x?

x(x + 2)(x - 5)