I need to take a sentence from input and sort the words
alphabetically using the C programming language.
Note: This is C not C++.
qsort and strtok not allowed
Answer Posted / yogesh bansal
#include <stdio.h>
int main()
{
char arr[100];
int count =0;
int j,i,k;
char temp;
printf("enter the string\n");
gets(arr);
for(i=0;arr[i]!='\0';i++)
count++;
printf("value of count is %d\n",count);
for(k=0;k<=count;k++)
{
for(j=0;j<count-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
puts(arr);
return 0;
}
This is the correct and working program.
| Is This Answer Correct ? | 6 Yes | 23 No |
Post New Answer View All Answers
What is the modulus operator?
What is the difference between mpi and openmp?
Differentiate fundamental data types and derived data types in C.
What is c definition?
What is structure in c definition?
What is the best organizational structure?
Where static variables are stored in c?
When should a type cast be used?
Why do we need a structure?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
Explain what is wrong with this program statement?
Why is %d used in c?
Tell us something about keyword 'auto'.
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
What is function definition in c?