answersLogoWhite

0


Best Answer

/*Program to accept names of 5 students and display them in alphabetic order*/

#include<conio.h>

#include<stdio.h>

#include<string.h>

void main()

{

int i=0,j=0;

char frame[5],temp[5];

clrscr();

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

{

printf("\nEnter student[%d]string",i);

scanf("%s",fname[1]);

}

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

{

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

{

if(strcmp(fname[i],fname[i])>0)

{

strcpy(temp,fname[i]);

strcpy(fname[i],fname[i]);

strcpy(fname[j],temp);

}

}

}

printf("The names of the students in alphabetic order is:");

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

{

printf("\n%s",fname[i]);

}

getch();

}

User Avatar

Wiki User

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

Wiki User

14y ago

#include

using std::cin;
using std::cout;

char names[5][256];

int main(int argc, char** argv)
{
for(int i = 0; i < 5; i++)
{
cout << "Enter Name #" << i + 1 << ": ";
cin.getline(names[i], 256);
}

cout << endl << endl;

for(int i = 0; i < 5; i++)
{
cout << "Name #" << i+1 << " = " << names[i] << endl;
}


}

There ya go,
Mrbiggbrain.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include<iostream>

#include<vector>

#include<string>

#include<algorithm>

using Actor = std::pair<std::string, std::string>;

using Actors = std::vector<Actor>;

struct comp {

bool operator()(const Actor& a, const Actor& b) {

return a.second<b.second ? true : !(b.second<a.second) ? a.first<b.first : false;

}

};

int main()

{

Actors actors = {{"John", "Wayne"}, {"Steve","McQueen"}, {"Bob","Hoskins"}, {"Bruce","Willis"}, {"Arnold","Schwarzenegger"}, {"Michael","Douglas"}, {"Kirk","Douglas"}};

std::cout << "Actors unsorted:\n" << std::endl;

for (size_t i=0; i<actors.size(); ++i)

std::cout << actors[i].first << ' ' << actors[i].second << std::endl;

std::cout << std::endl;

std::sort (actors.begin(), actors.end(), comp());

std::cout << "Actors sorted by surname:\n" << std::endl;

for (size_t i=0; i<actors.size(); ++i)

std::cout << actors[i].first << ' ' << actors[i].second << std::endl;

std::cout << std::endl;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Here is the c code:

#include

#include


void

swap(

char

str1[],

char

str2[]){

//helper function for swapping two strings

char

temp[50

];

strcpy(temp, str1);

strcpy(str1,str2);

strcpy(str2, temp);

}


void

sort( char

names[5

][50

] ){

int

i, j;

for

( i=

0

; i<

5

-

1

; i++){

//using bubble sort technique

for

( j=0

; j<5

-i-1

; j++){

if

( strcmp(names[j], names[j+1

]) > 0

)

swap(names[j], names[j+1

]);

}

}

}

int

main(){

char

names[5

][50

];

int

i;

printf(

"Enter the five names:\n");

for

( i=0

; i<5

; i++)

scanf("%49s"

, names[i]);

sort(names);

for

( i=0

; i<5

; i++)

printf("%s\t"

, names[i]);

printf("\n"

);

return

0

;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C Program to accept 5 names from user and store these names into an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a C program to accept roll numbers and names of 10 student using array and display the names?

Well, we're not going to do it for you.There's some example code and tutorials at http://www.cplusplus.com/doc/tutorial/ . It's for C++, but the code is simple enough that it shouldn't make a difference. Adapt that, and it should do exactly what 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.


How is an array name interpretedwhen it is passed to a function?

An array is still an array, regardless of how you pass it into functions. It is still an array-type variable at the beginning of a function. However, the function itself may manipulate the array by "imploding" it into a string with a delimiter, using array values with only specific keys, and such.


Write code that prints the values stored in an array called names backwards?

In your main method: // Declare and initialize the array String names[] = {"Ana", "Bertha", "Cecilia", "Dora", "Emily"}; // Print backwards for (int i = names.length - 1; i &gt;= 0; i--) System.out.println(names[i]); If you want to print the individual texts backwards (like "Dora" --&gt; "aroD"), the StringBuffer class offers a method to do precisely that.


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.

Related questions

Write a C program to accept roll numbers and names of 10 student using array and display the names?

Well, we're not going to do it for you.There's some example code and tutorials at http://www.cplusplus.com/doc/tutorial/ . It's for C++, but the code is simple enough that it shouldn't make a difference. Adapt that, and it should do exactly what you want.


What is program style?

Program style refers to the way you write a program code. A good style is usually characterized by proper indentation, meaningful variable names, etc.


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.


How insert data into array in php?

There's several ways: 1) You can put square brackets on the end of a variable to create an array key inside that variable: $names['first'] = "john" $names['last'] = "smith" 2) You can use the array function: $names = array('first' =&gt; "john", 'last =&gt; "smith"); a lot of people set this function out like this: $names = array( 'first' =&gt; "john", 'last' =&gt; "smith" ); it makes it easier to read hope this helps


How is an array name interpretedwhen it is passed to a function?

An array is still an array, regardless of how you pass it into functions. It is still an array-type variable at the beginning of a function. However, the function itself may manipulate the array by "imploding" it into a string with a delimiter, using array values with only specific keys, and such.


Write code that prints the values stored in an array called names backwards?

In your main method: // Declare and initialize the array String names[] = {"Ana", "Bertha", "Cecilia", "Dora", "Emily"}; // Print backwards for (int i = names.length - 1; i &gt;= 0; i--) System.out.println(names[i]); If you want to print the individual texts backwards (like "Dora" --&gt; "aroD"), the StringBuffer class offers a method to do precisely that.


Is there an official translation for names of cities and names for streets in Hebrew do you write the Hebrew name for street I know but this program do not let me write it or the name and then street?

There is no official translation, but there is an official system in Israel of transliterating Hebrew letters


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.


Accept ten names and print the given names in opposite order using array of pointers?

#include&lt;stdio.h&gt; #include&lt;string.h&gt; #include&lt;conio.h&gt; void main() { int i; char a[10]; printf("enter ten names one by one"); for(i=0;i&lt;=9;i++) { scanf("%s\n",a); } for(i=9;i&lt;=0;i--) { printf("names are %s\n"); } getch(); }


How do you write your own music on synthesia?

Synthesia is a training program, not a composing or recording program. It was originally called 'Piano Hero', but had to change names under a threat of lawsuit from Activision.


How can I write a code in Java that returns the number of names in a given array that end in either ie or y?

int getNumMatches(String[] names) { int numMatches = 0; for(String name:names) { if(name.endsWith("ie") name.endsWith("y")) { ++numMatches; } } return numMatches; }


What to write on my daughter's first year of dance for program book?

Write her name, age , place of the recital , what dance and to what music she performed, and the names of any students that accompanied her in the performance.