Write a C program that reads in a list of letters, sorts them alphabetically and
ID: 667927 • Letter: W
Question
Write a C program that reads in a list of letters, sorts them alphabetically and prints them to the screen. The program must adhere to the following specifications:
a) The program must ask the user how many letters can be expected.
b) The program then should ask the user for all the (capital or lower-case) letters and should make sure the letters entered are valid letters (and not symbols).
c) Capital letters should be sorted before lower-case letters.
d) Your program must use dynamic memory allocation for all arrays needed. In addition, pointers must be used for all operations that access the array(s). Thus, your program must not include any square brackets (‘[‘ or ‘]’) anywhere in the code.
e) Your program must consist of a main()function, a sort(char *a, int size) function, and a swap(char *x, char *y) function.
Explanation / Answer
#include #include #include void main() { char a[40],t; int i,j; clrscr(); printf(" Enter the String :- "); scanf("%s",a); for(i=0;a[i]!='';i++) { for(j=i+1;a[j]!='';j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("the alphabet wise is :- %s",a); getch(); } /* ****** OUTPUT ****** Enter the String : world the alphabet wise is dlorw */Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.