NEP -DATA STRUCTURE

PART-A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

6. Write a C Program to read the names of cities and arrange them alphabetically using bubble sort.

 
  
 
 
 
 /* 6. Write a C Program to read the names of cities and arrange them alphabetically using bubble sort.*/

#include< stdio.h>
#include< string.h>
main(){
   int i,j,n;
   char str[100][100],s[100];
   printf("Enter number of names :\n");
   scanf("%d",&n);
   printf("Enter names in any order:\n");
   for(i=0;i< n;i++){
      scanf("%s",str[i]);
   }
   for(i=0;i< n;i++){
      for(j=i+1;j< n;j++){
         if(strcmp(str[i],str[j])>0){
            strcpy(s,str[i]);
            strcpy(str[i],str[j]);
            strcpy(str[j],s);
         }
      }
   }
   printf("\nThe sorted order of names are:\n");
   for(i=0;i< n;i++){
      printf("%s\n",str[i]);
   }
}