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
What is an array? What the different types of arrays in c?
What is variables in c?
What is the difference between local variable and global variable in c?
Write a program to know whether the input number is an armstrong number.
Why do we need functions in c?
Write a C program linear.c that creates a sequence of
processes with a given length. By
sequence it is meant that each created process has exactly
one child.
Let's look at some example outputs for the program.
Here the entire process sequence consists of process 18181:
Sara@dell:~/OSSS$ ./linear 1
Creating process sequence of length 1.
18181 begins the sequence.
An example for a sequence of length three:
Sara@dell:~/OSSS$ ./linear 3
Creating process sequence of length 3.
18233 begins the sequence.
18234 is child of 18233
18235 is child of 18234
........ this is coad .... BUt i could not compleate it .....:(
#include
What is meant by preprocessor in c?
Where we use clrscr in c?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
The statement, int(*x[]) () what does in indicate?
What do you mean by recursion in c?
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?
Explain the use of fflush() function?
What is the value of c?
Why is c called "mother" language?