Write a program to
read a string through keyboard and sort it using bubble sort.
- #include<stdio.h>
- #include<string.h>
- int main(){
- int i, j, n;
- char str[25][25], temp[25];
- printf("Enter the number of string : ");
- scanf("%d", &n);
- printf("\nEnter %d strings : \n", n);
- for(i=0; i<=n; i++)
- gets(str[i]);
- for(i=0; i<=n; i++)
- for(j=i+1; j<=n; j++) {
- if(strcmp(str[i], str[j])>0) {
- strcpy(temp, str[i]);
- strcpy(str[i], str[j]);
- strcpy(str[j], temp);
- }
- }
- printf("\n\nSorted Strings :");
- for(i=0; i<=n; i++)
- puts(str[i]);
- return 0;
- }
একটি মন্তব্য পোস্ট করুন