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

Answers were Sorted based on User's Feedback



I need to take a sentence from input and sort the words alphabetically using the C programming la..

Answer / chumurva

its working but not correct.

Is This Answer Correct ?    6 Yes 0 No

I need to take a sentence from input and sort the words alphabetically using the C programming la..

Answer / naveen

Then which one is the answer. i think the above one works
perfectly and they both will yield you the same results
which you wanted.

is this a tricky qustion? if so whats the answer for this

Is This Answer Correct ?    2 Yes 3 No

I need to take a sentence from input and sort the words alphabetically using the C programming la..

Answer / 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

I need to take a sentence from input and sort the words alphabetically using the C programming la..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char a[50],temp;
int count=0;
printf("enter the string");
gets(a);
for(int i=0;a[i]!='\0';i++)
count++;
for(i=0;i<count;i++)
{
for(int j=0;j<count;j++)
{
if(a[j]=a[j+1];
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\n");
puts(a);
getch();
}

thank u

Is This Answer Correct ?    1 Yes 27 No

Post New Answer

More C Interview Questions

There are 8 billiard balls, and one of them is slightly heavier, but the only way to tell was by putting it on a weighing scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?

5 Answers   Microsoft, TCS,


what is computer

4 Answers  


we have to use realloc only after malloc or calloc ? or we can use initially with out depending on whether we are using malloc or calloc in our program ?

2 Answers  


how to return 1000 variables from functio9n in c?plz give me code also

6 Answers  


How do you define a string?

0 Answers  


AMMONG THE 4 STROAGE CLASSES IN C, WHICH ONE FASTEST?

13 Answers   HCL,


What is the purpose of the fflush() function in C?

2 Answers  


where do we use volatile keyword?

1 Answers  


What are extern variables in c?

0 Answers  


How would you print out the data in a binary tree, level by level, starting at the top?

6 Answers   Amazon, Microsoft,


Program to find largest of three numbers without using comparsion operator?

3 Answers  


What is modeling?

0 Answers  


Categories