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 preprocessor with example?
Does free set pointer to null?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
Can you write the algorithm for Queue?
Is c weakly typed?
What are the 3 types of structures?
what is a constant pointer in C
What are control structures? What are the different types?
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
Write a program of prime number using recursion.
how logic is used
What is infinite loop?
How can I change their mode to binary?
Explain function?
Difference between malloc() and calloc() function?