google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to sort the given n names - 2nd puc computer science

Write a c program to sort the given n names

Write a c program to sort the given n names

#include<conio.h>

#include<string.h>

void main()

{

char name[20][10],temp[10];

int i,j,n;

clrscr();

printf("How many names? ");

scanf("%d",&n);

printf("Enter %d names:\n",n);

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

scanf("%s",name[i]);

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

{

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

         {

                  if(strcmpi(name[i],name[j])>0)

                  {

                           strcpy(temp,name[i]);

                           strcpy(name[i],name[j]);

                           strcpy(name[j],temp);

                  }

         }

}

printf("Sorted names are\n");

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

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

getch();

}

Output:

How many names? 3

Enter 3 names:                                                                 

radha                                                                          

krishna                                                                         

gopal                                                                          

Sorted names are                                                               

gopal                                                                           

krishna                                                                        

radha  
Write a c program to sort the given n names Write a c program to sort the given n names Reviewed by Vision Academy on December 22, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.