Write a c program to accept 5 names from users and store these names into an array.sort these array elements in alphabetical order.
#include<stdio.h> void main() { int i,j,d; char ch[20][30],tmp[30]; clrscr(); printf("\n enter the no of string\n"); scanf("%d",&d); printf("\n entert %d string",d); for(i=0;i<=d;i++) { gets(ch[i]); printf("\n\n\n"); printf("\nenter string are\n"); } for(i=0;i<=d;i++) { printf("\n%s",ch[i]); } for(i=0;i<=d;i++) { for(j=i+1;j<=d;j++) { if(strcmp(ch[i],ch[j])>0) { strcpy(tmp,ch[i]); strcpy(ch[i],ch[j]); strcpy(ch[j],tmp); } } } printf("\n\n\n"); printf("\n sorted string are:"); for(i=0;i<=d;i++) printf("\n%s",ch[i]); getch(); } /*---------------------------------output---------------------- enter the no of string 5 entert 5 string enter string are ankit enter string are aditya enter string are ramesh enter string are sorab enter string are rohit enter string are ankit aditya ramesh sorab rohit sorted string are: aditya ankit ramesh rohit sorab*/
Write a c program to accept 5 names from users and store these names into an array.sort these array elements in alphabetical order.
Reviewed by
on
April 24, 2015
Rating: