C Program To Sort A Given Number Of Strings.
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
char str[4][10];
int i;
clrscr();
for( i = 0; i < 4; i++ )
{
printf(“ \nEnter name %d: ”, i+1 );
scanf(“ %s ”, str[i] );
}
printf(“\n Original Order\n”);
for(i = 0; i < 4; i++ )
printf(“ %s\t ”, str[i] );
for(i = 0; i < 4; i++ )
{
for(j = i + 1; j < 4; j++ )
if( strcmp(str[i], str[j]) > 0 )
{
strcpy( temp, str[i] );
strcpy( temp, str[i], str[j] );
strcpy( str[j], temp );
}
}
printf(“\n Sorted Order\n”);
for( i = 0; i < 4; i++ )
printf(“ %s\t ”, str[i]);
getch();
}
OUTPUT:
Enter name 1: John
Enter name 2: Mac
Enter name 3: William
Enter name 4: Allen
Original Order
John Mac William Allen
Sorted Order
Allen John Mac William
ALSO READ:
-- Program to accept a string and print it by using the while loop.
-- Program to accept a string in upper case and print it in lower case.
-- Program to accept a string in any case and print it by another case.
-- Program to accept a string and print each word in new line.
-- Program to accept a string and count no of capital letters, no. of small letters and no. of special characters.
-- Program to accept a string and find the length of the given string by using functions.
-- Program to accept a string and print the reverse of the given string.
-- Program to accept a string and check whether the given string is palindrome or not.
-- Program to accept two string and compare the strings are equal or not.
-- Program To Find Out The No. Of Times A Character Is Present In The String.
-- Program To Accept A String & Find Out Whether This Character Is Present In The String.
-- Program To Accept A String & Display Number Of Each Vowels.
-- Program To Accept A String & Display Number Of Vowels.
-- Program To Accept A String & Display Vowels.
-- Program To Accept Two Strings & Display Combination Of Two Strings.
-- Program To Accept Two Strings & Display The Largest String.
-- Program To Accept A String & Display It's Alternate Characters In Reverse.
-- Program To Accept A String & Display It's Substring.
-- Program To Accept A String & Display Alternate Characters In Either Case.
-- Program To Accept A String & Display Its Alternate Characters.
-- Program To Accept A String & Display In Reverse.
-- Program To Accept A String & Display It.
-- Program On Strings Into Array Of Pointers.
-- Program To Concatenate Two Strings.
-- Program To Compare Two Strings.
... Back To C Program Index.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com