ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
Question

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
 Question Submitted By :: J
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
#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 ?    0 Yes 22 No
Vignesh1988i
 
  Re: 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
# 2
#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 ?    4 Yes 19 No
Yogesh Bansal
 
 
 
  Re: 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
# 3
its working but not correct. 
Is This Answer Correct ?    5 Yes 0 No
Chumurva
 
  Re: 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
# 4
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
Naveen
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
While(1) { } when this loop get terminate is it a infinite loop?   5
write a function which accept two numbers from main() and interchange them using pointers?   3
how to execute with out main in cprogram Infosys 15
Write a program that takes a 5 digit number and calculates 2 power that number and prints it TCS 5
How to run c Program without using IDE of c. means if program made in notepad.then how to compile by command prompt. TCS 1
write a own function for strstr LG-Soft 1
Write a program to print all the prime numbers with in the given range ABC 8
can any one tell that i have a variable which is declared as static but i want this variable to be visible to the other files? how?   2
what wud be the output? main() { char *str[]={ "MANISH" "KUMAR" "CHOUDHARY" }; printf("\nstring1=%s",str[0]); printf("\nstring2=%s",str[1]); printf("\nstring3=%s",str[2]); a)string1=Manish string2=Kumar string3=Choudhary b)string1=Manish string2=Manish string3=Manish c)string1=Manish Kumar Choudhary string2=(null) string3=(null) d)Compiler error Infosys 9
Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words. Demonstrate the usage of this function from a main program. Example: Parameter: “jack and jill went up a hill” Return Value: “kcaj dna llij tnew pu a llih” Mind-Tree 4
main() { int a; a=++100; printf("%d",a); getch(); }   4
how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright © 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com