Given an array of characters which form a sentence of
words, give an efficient algorithm to reverse the order of
the words (not characters) in it?
Answer Posted / tarak
#include<stdio.h>
int main()
{
char *p="i am working in TechM";
char *s,*temp;
char a[20];
int i=0;
s=p;
while(*p != '\0')
p++;
while(s != p){
while(*(--p)!=' ');
temp=p;
p++;
while(*p != '\0' && *p != ' ')
{
a[i++]=*p;
p++;
}
a[i++]=' ';
p=temp;
p--;
}
while(*s != ' ')
a[i++]=*s++;
a[i] = '\0';
printf("%s \n",a);
}
~
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
In c programming language, how many parameters can be passed to a function ?
What is static identifier?
How to define structures? ·
What is #include stdlib h?
Write a program to swap two numbers without using the third variable?
Write a program to check palindrome number in c programming?
Why is c called a structured programming language?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.
Is using exit() the same as using return?
What is masking?
List out few of the applications that make use of Multilinked Structures?
What is the correct declaration of main?
What is wrong with this initialization?
Here is a good puzzle: how do you write a program which produces its own source code as output?
What is time null in c?