answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main(void)

{

int i,k,n;

char name[50],temp;

printf("\n enter no.of persons");

scanf("%d",&n);

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

gets(name[i]);

for(k=0;k<n-1;k++)

{

for(i=0;i<n-k-1;i++)

{

if(strcmp(name[i],name[i+1])>0)

{

strcpy(temp,name[i]);

strcpy(name[i],name[i+1]);

strcpy(name[i+1],temp);

}

}

}

printf("\n sorted list \n");

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

puts(name[i]);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<conio.h>

main()

{

char names[40][20],temp[20];

int i,n,j;

printf("How many names?:");

scanf("%d",&n);

printf("Enter the %d names one by one:",n);

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

scanf("%s",names[i]);

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

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

if(strcmp(names[i],names[j])>0)

{

strcpy(temp,names[i]);

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

strcpy(names[j],temp);

}

printf("Names in Alphabetical order");

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

printf("%s",names[i]);

getche();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago
Answer 1This program is for java.

class project_4

{

/*Enter a sentence*/

public static void main(String sent)

{

int i,x,length;

length=sent.length();

char temp;

char ch[]=new char[length];

for(i=0;i

{

ch[i]=sent.charAt(i);

}

for(i=0;i

{

for(x=0;x

{

if(ch[x]>ch[x+1])

{

temp=ch[x];

ch[x]=ch[x+1];

ch[x+1]=temp;

}

}

}

for(i=0;i

System.out.print(ch[i]);

}

}

Answer 2public static final String sort(final String str) {

final char[] chars = str.toCharArray();

Arrays.sort(chars);

return String.valueOf(chars);

}

Answer 3

import java.io.*;

class Alphabetical

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the String: ");

String s=in.readLine();

for(short i=65;i<91;i++)

{

for(short j=0;j

{

char ch=s.charAt(j);

if(ch==i ch==i+32)

System.out.print(ch);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

// Names are stored here

final ArrayList<String> names = new ArrayList<String>();

// Get input from standard in

final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

// Prompt for input

System.out.println("Enter names to sort: ");

// Get input

String currentLine;

while ((currentLine = in.readLine()) != null) {

// A blank line equals the end of input

if (currentLine.equals("")) {

break;

}

names.add(currentLine);

}

// Remember to close our input

in.close();

System.out.println("Sorting: " + names);

// Let Java do our sorting for us.

Collections.sort(names);

System.out.println("Sorted: " + names);

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

public class sort1

{

public static void main(String args[])

{

int len = args.length;

if(len == 0)

{

System.out.println("No Arguments");

System.exit(0);

}

char str[] = args[0].toCharArray();

char temp;

for(int i = 0; i<len ; i++)

{

for(int j = 0; j<len ; j++)

{

if(str.CharAt(j) > str.CharAt(j+1))

{

temp = str[j];

str[j] = str[i];

str[i] = temp;

}

}

}

for(int i = 0 ; i< len; i++)

{

System.out.println(str[i]);

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

I assume you want to sort the names alphabetically. Java has a built in alphabetical sorting command. You first need to put your strings into an array, and then use the method java.util.Arrays.sort(String Array). The method Collections.sort(List Name) will then sort your list into alphabetical order. Keep in mind you will need to import these methods.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Write a program using a while loop to print the numbers 2 to 10 in increments of two. The output of your program should be 2 4 6 8 10

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

TL Kidd Kiddle Graphics Kids Kommotion H Kidby The Kids Art Academy

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program which will read a string and rewrite it in the alphabetical order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


Write a program in java to display a string message using Servlets?

i dont no string for servlate


Write the program in Linux to find the reverse of any string?

i am sam


Write a program to find the length of a string in shellscript?

This is an assignment not a question.


How do you write a c program to find a word in a string?

what is if(!(str[i]==32))


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


How do you write a c program to find the smallest word in a string?

what is if(!(str[i]==32))


Write a program convert a string from uppercase to lower case and vice-versa without using string tolower and string toupper commands in TCL?

[ string toupper $str ] or [ string tolower $str ]


Do I need to write a program to find a substring in a given string in c plus plus?

No.


Write a java program to initialize array of string with the days of the week?

final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.