C Programming code for bubble sorting the Strings – KLETech

Write a Modular C Programming Code for Sorting Strings | Sentence Ascending and Descending?

CODE:

#include<stdio.h>
#include<string.h>
void sort(char str[]);
main()
{
char str[1000];
printf("Enter the word\n");
scanf("%s",str);
sort(str);
printf("\nWord after sorting each character = %s\n",str);
}
void sort(char str[])
{
int i,j;
char temp;
for(i=0;str[i]!='\0';i++)
{
for(j=0;j<strlen(str)-1-i;j++)
{
if(str[j] > str[j+1])
{
temp = str[j];
str[j] = str[j+1];
str[j+1]=temp;
}
}
}
}

 

OUTPUT

Enter the word
qwertyuiopasdfghjklzxcvbnm

Word after sorting each character = abcdefghijklmnopqrstuvwxyz

Process returned 0 (0x0) execution time : 15.719 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!