answersLogoWhite

0


Best Answer

, since you seem to be needing help with your homework, I can give you some psuedo code to help you on your way!

[CODE]

DECLARE ARRAY names[10]

FOR i = 0 TO 9

names[i] = READ INPUT FROM USER

ENDFOR

CALL FUNCTION sort WITH PARAMETERS names, 10

[/CODE]

In the event that you have to create your own sorting function, I can give you some pseudo-code for the selection sort - a relatively easy-to-write sorting algorithm which doesn't involve any complicated data structures, or more advanced programming patterns, such as recursion.

[CODE]

FUNCTION sort WITH PARAMETER ARRAY names[], size

FOR i = 0 TO size

min = i

FOR j = i + 1 TO size

//Find the smallest unsorted element in the list

IF names[min] > names[j] THEN min = j

END FOR

SWAP names[i] AND names[min]

END FOR

END FUNCTION

[/CODE]

The above function sorts in ascending order. The smallest element will be located at names[0], and the largest will be at names[size].

If you are allowed to, you may be able to use C's builtin strcmp() function to compare strings (found in #include <string.h>, or #include <cstring> for a C++ compiler). PLEASE REMEMBER that you can not compare strings directly in C!!! A C-string is nothing more than a memory address. If you attempt to compare two strings directly, then the compiler will NOT compare the strings, but the memory addresses where the strings are located! If you can't use strcmp(), you will have to write your own string comparing function.

When reading input from the user, you will need to use scanf() for C. Also remember that C does not do any memory management for you, so you need to make sure you have enough space in your character arrays to read in a string from the user. Because you have multiple names, you will need to create an array of arrays. Something similar to this: "char names[NUMBER_OF_NAMES][CHARACTERS_IN_A_NAME];" where NUMBER_OF_NAMES = 10 and CHARACTERS_IN_A_NAME is an arbitrary number, large enough to store a name (I would pick something like 100).

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to accept alist of 10 namews input by user then display the sorted list of names back to the user?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a shell program called whos to display a sorted list of the logged in usersJust display the user names and no other information?

The 'users' command should do that; you don't need to write a shell script to get that information in that format.


What is agree in principle?

To broadly accept an idea or suggestion, but subject to some smaller issues being sorted out.


Into what 3 categories is paper sorted?

where and how is paper sorted? where and how is paper sorted?


How do you get sorted on harrypottercom?

You cannot get sorted on that website. However, you can be sorted on Pottermore.


Write a c plus plus program that display sorted value?

You cannot sort a single value. You need two or more values. In order to display sorted values you first have to sort the values. The simplest way is to use an associative container such as std::set or std::map. If you need to allow duplicates, use std::multiset or std::multimap instead. Data elements are sorted as they are added. The only difference between a set and a map is that a set stores the value as a key, whereas a map associates a value with a key. Once added, the key cannot be changed, so if you need to edit values, use a map. If you need to change a key, you must erase the original key and add a new key.


How do poorly sorted and well sorted sediments differ?

the well sorted is on the left & the poorly sorted is on the right .. It all depends on the arrangement and size of the rocks


How can data be sorted in a database?

it can be sorted by files kamran :)


Do kettle lakes contain sorted or unsorted sediments?

sorted


What is the past participle of sort?

The past participle of &quot;sort&quot; is &quot;sorted.&quot; For example, &quot;I have sorted the documents alphabetically.&quot;


How are living things sorted?

Living things are sorted intio species


What is the duration of Sorted film?

The duration of Sorted - film - is 1.63 hours.


What does sorted mean?

To order the records in the answer to a query in a particular way.